将jms属性映射到RabbitMQ



我们使用spring集成来使用MQSeries和RabbitMQ通信组件。

对于MQseries,有许多JMS属性可供客户使用。

我们想在输入和输出之间添加一个中间函数,该函数对这些属性进行映射(从mqseries获取jms_priority,并在输出消息中放入RabbitMQ的属性"priority")。

如果没有特定的属性JMS,它工作得非常好

下面的代码我们使用:

<int:channel id="input" ></int:channel>
<int-jms:message-driven-channel-adapter id="jmsIn" connection-factory="connectionFactoryCaching"  channel="input" ...>
<int:service-activator id="sa1" input-channel="input" ref="serviceBean"  output-channel="output"/>
<bean id="serviceBean" class="com.poc.ServiceActivator"> </bean>
<int:channel id="output" ></int:channel>
<int-amqp:outbound-channel-adapter channel="output"  .../>
import org.springframework.amqp.core.MessageProperties;

ServiceActivator代码:

public class ServiceActivator {
public org.springframework.amqp.core.Message convertMessageMQSeriesToRabbit (Message obj){
MessageProperties messageProperties = new MessageProperties();
try {
messageProperties.setCorrelationId(obj.getJMSCorrelationID());
System.out.println("getJMSReplyTo "+obj.getJMSReplyTo());
System.out.println("getJMSPriority "+obj.getJMSPriority());
messageProperties.setPriority(obj.getJMSPriority());
System.out.println("getJMSType "+obj.getJMSType());
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}   

这样做对吗?在convertMessageMQSeriesToRabbit方法中,应该向出站传递什么类型的返回对象?org.springframework.amqp.core.消息?

在这种方法中,我们希望用相应的JMS值填充所有RabbitMQ消息属性(content_type、content_encoding、priority、correlation_id、reply_to、expiration、message_id、timestamp、type、user_id、app_id、cluster_id)。

我们还需要用另一种方式(inboud rabbitMQ=>outbound mqseries)

不,Spring Integration使用自己的抽象org.springframework.messaging.Message<?>。您不需要直接与它交互,只需使用一个标头富集器即可。

常数见JmsHeadersAmqpHeaders

<header-enricher id="headerEnricherWithShouldSkipNullsFalse" input-channel="fromJms" output-channel="toRabbit">
<header name="amqp_correlationId" expression="headers.jms_correlationId"/>
...
</header-enricher>

对于AMQP优先级,使用标准IntegrationMessageHeaderAccessor.PRIORITY值。

另请参阅DefaultAmqpHeaderMapperDefaultJmsHeaderMapper,了解适配器如何从Message<?>映射到RabbitMQ和JMS消息。

最新更新