简体   繁体   中英

Spring RabbitMQ - xml configuration - manual ack

I have defined configuration for rabbit in spring:

<rabbit:connection-factory id="amqpConnectionFactory" addresses="${amqp.host}:${amqp.port}"
                           thread-factory="rabbitThreadFactory"
                           cache-mode="CHANNEL"
                           channel-cache-size="25"
                           username="${amqp.user}"
                           password="${amqp.pass}"
                           virtual-host="${amqp.vhost}"/>

<rabbit:admin connection-factory="amqpConnectionFactory" id="rabbitAdmin"/>

<rabbit:topic-exchange id="motoTopicExchange" name="moto.ex.topic" >
    <rabbit:bindings>
        <rabbit:binding pattern="moto.*.speed" queue="motoQueue8"/>
        <rabbit:binding pattern="moto.*.tour" queue="motoQueue9"/>
        <rabbit:binding pattern="moto.*.naked" queue="motoQueue10"/>
    </rabbit:bindings>
</rabbit:topic-exchange>

<rabbit:queue id="motoQueue8" name="moto.queue.8"/>
<rabbit:queue id="motoQueue9" name="moto.queue.9"/>
<rabbit:queue id="motoQueue10" name="moto.queue.10"/>

<rabbit:template id="rabbitTemplate"
                 connection-factory="amqpConnectionFactory"
                 retry-template="retryTemplate"
                 message-converter="rabbitJsonConverter"/>

<bean id="rabbitJsonConverter" class="org.springframework.amqp.support.converter.Jackson2JsonMessageConverter"/>

<rabbit:listener-container connection-factory="amqpConnectionFactory" message-converter="rabbitJsonConverter"
                           max-concurrency="10" acknowledge="auto">
    <rabbit:listener ref="amqpService8" method="handleSimple" queues="motoQueue8"/>
    <rabbit:listener ref="amqpService9" method="handleSimple" queues="motoQueue9"/>
    <rabbit:listener ref="amqpService10" method="handleSimple" queues="motoQueue10"/>
</rabbit:listener-container>

Where handleSimple method in listeners consumes object for example Motorcycle (there is also json conversion when sending thought amqp).

  1. How could I manually ack massage which was passed into listeners ?
  2. Is it possibleto get MessageHeader alongside object (Motorcycle) ?

I don't want to configure listeners thought annotation.

Thanks

What is the desire for manual acks? It's quite unusual to need them; the container will take care of acking for you.

To use manual acks, you need a ChannelAwareMessageListener implementation.

You would also have to invoke the message converter yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM