有一个类似的问题Procedure to migrate from IBM MQ to ActiveMQ并且已经关闭,但无论如何我都会尝试。 我们的客户希望从WebSphere MQ迁移到Active MQ。在上述问题中,有人说,对于JMS而言,理论上的这种迁移将包括应用程序重新配置。我们的客户说他们的应用程序使用自动生成的.bindings文件。那么,是否可以通过编辑.binding文件并将活动mq的.jars放到java类路径中来使应用程序与Active MQ一起工作,还是需要一些其他配置?
答案 0 :(得分:2)
要检查这一点,我尝试了以下
a)使用JMSAdmin创建WMQ绑定文件。一旦我创建了QCF和队列,我就能够通过JMS查找发送消息并发送消息。
b)对于设置生成.bindings文件的AMQ,IBM有一些示例代码generate the bindings file.
一旦完成,我使用完全相同的代码发送消息,消息完美地发送到AMQ和WMQ
以下是我能够互操作的示例代码。
public void sendMessages() {
ConnectionFactory connectionFactory;
Connection con = null;
Session session = null;
MessageProducer producer = null;
//create initial context properties
Properties initialContextProperties = new Properties();
initialContextProperties.put("java.naming.factory.initial", "com.sun.jndi.fscontext.RefFSContextFactory");
initialContextProperties.put(Context.PROVIDER_URL, "file:/C:/JNDI-Directory/AMQ");
initialContextProperties.setProperty("transport.jms.security.authentication", "none");
try {
InitialContext initialContext = new InitialContext(initialContextProperties);
//create connection factory object
//ivtQCF - created connection factory object in IBM-MQ
connectionFactory = (ConnectionFactory) initialContext.lookup("confact2");
con = connectionFactory.createConnection();
con.start();
session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
//localq - created queue in IBM-MQ
Destination destination = (Destination) initialContext.lookup("dest");
producer = session.createProducer(destination);
String msg = "SAMPLE MESSAGE PLACED TO QUEUE";
TextMessage textMessage = session.createTextMessage(msg);
producer.send(textMessage);
con.close();
session.close();
producer.close();
} catch (NamingException e) {
throw new RuntimeException("Unable to send jms messages", e);
} catch (JMSException e) {
throw new RuntimeException("Unable to send jms messages", e);
}
}