开发者

IBM MQ vs JMS - Spring Implementation

开发者 https://www.devze.com 2023-04-09 06:40 出处:网络
I开发者_如何学Python am working on a Spring application where we have implemented code to send messages through IBM MQ.

I开发者_如何学Python am working on a Spring application where we have implemented code to send messages through IBM MQ.

Now we have been advised not to directly use MQ APIs directly and instead use JMS.

The steps I followed :

  1. created a JNDI name to connect to the Message queue configured as:

    <bean id="emailQueueDestination" class="org.springframework.jndi.JndiObjectFactoryBean" lazy-init="true">
            <property name="jndiName" value="<<JNDI name of Queue" >>/>
    </bean>
    
  2. I need a connecton factory object to connect to the JMS Provider and I have configured it as:

    <bean id="emailQueueConnectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
      <property name="queueManager" value="" />
          <property name="hostName" value="" />
      <property name="channel" value="" />
      <property name="port" value="1414" />
    </bean>
    

Further I have injected the above 2 beans in JMSTemplate class:

<bean id="emailQueueTemplate" class="org.springframework.jms.core.JmsTemplate" lazy-init="true">
        <property name="connectionFactory" ref="emailQueueConnectionFactory" />
        <property name="defaultDestination" ref="emailQueueDestination" />
    </bean>

Now since my purpose is to remove dependency on MQ APIs, do you think the configuration above (especially for connection factory) looks good?


If your code doesn't refer to any of the MQ classes (i.e. it references that bean only as a JMS ConnectionFactory and you don't rely on any other non-standard features of MQ, then this should make your code reasonably easy to port.

I wouldn't bet that switching to another product would require zero code changes (many JMS implementations seem to have some interesting peculiarities), but you're definitely on the right way.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号