Receiving RabbitMQ message from one channel, set the messageId in the transformer and send it to other channel using Spring Integration
我是 RabbitMQ 和 Spring 集成的新手。
我有一个用例来使用来自通道的 JSON 消息,将其转换为对象。我需要在对象中设置的字段之一是我们从 rabbitMQ 收到的消息的消息 Id(delivery.getEnvelope().getDeliveryTag()),我们需要在所有业务逻辑之后进行 ack 处理。
如何使用spring集成来做到这一点?
这是我的 xml 配置。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <bean id="devRabbitmqConnectionFactory" class="com.rabbitmq.client.ConnectionFactory"> <property name="brokerURL" value="#{props[rabbitmq_inputjms_url]}" /> <property name="redeliveryPolicy" ref="redeliveryPolicy" /> </bean> <bean id="devJMSCachingConnectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory"> <property name="targetConnectionFactory" ref="devRabbitmqConnectionFactory" /> <property name="sessionCacheSize" value="10" /> <property name="cacheProducers" value="false" /> </bean> <int-jms:channel id="devJMSChannel" acknowledge="transacted" connection-factory="devJMSCachingConnectionFactory" message-driven="false" queue-name="devJMSChannel"> </int-jms:channel> <bean id="redeliveryPolicy" class="org.apache.activemq.RedeliveryPolicy"> <property name="initialRedeliveryDelay" value="5000" /> <property name="maximumRedeliveries" value="5" /> </bean> <int:transformer id="devObjectTransformer" input-channel="devJMSChannel" ref="devService" method="readEventFromRabbitMQ" output-channel="devPacketChannel"> <int:poller fixed-rate="10" task-executor="devObjectTransformerExecutor" /> </int:transformer> |
transformer 方法"readEventFromRabbitMQ" 从msg.getPayload() 中获取消息字符串,将其转换为对象并发送到输出通道。但不确定如何在转换器类中获取消息 ID。有人可以帮我解决这个问题吗?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public List<DevEventRecord> readEventFromRabbitMQ(Message<EventsDetail> msg){ DevEventRecord[] eventRecords=null; EventsDetail expEvent = null; long receivedTime =System.currentTimeMillis(); int packetId = -1; try{ monitorBean.incrementDeviceExceptionPacketCount(); expEvent = msg.getPayload(); LogUtil.debug("readExceptionEvent :: consumed JMS Q"+expEvent); eventRecords = dispatchPacket(expEvent); } catch(ProcessingException pe){ notifyAck(expEvent.getUniqueId(),,,,); } catch(Exception ex){ notifyAck(expEvent.getUniqueId(),,,,); LogUtil.error("Exception occured while reading object in readEvent ,"+ex.toString()); } return getEventRecordList(eventRecords); } |
我不明白你为什么混合
请使用