Jms 使用IBM Websphere MQ时如何发送和接收消息

Jms 使用IBM Websphere MQ时如何发送和接收消息,jms,Jms,可能重复: 我知道JMS是sun提供的消息传递标准,IBM Websphere MQ是JMS的实现 我一直使用JMS,从未使用MQ。所以我有几个问题 使用JMS,我将在应用服务器中配置连接工厂和队列,并使用下面的代码发送和接收消息。在JMS中,我们使用javax.JMS.*包 发送消息的代码 Context context = new InitialContext(); QueueConnectionFactory queueConnectionFactory =`enter code her

可能重复:

我知道JMS是sun提供的消息传递标准,IBM Websphere MQ是JMS的实现

我一直使用JMS,从未使用MQ。所以我有几个问题

使用JMS,我将在应用服务器中配置连接工厂和队列,并使用下面的代码发送和接收消息。在JMS中,我们使用javax.JMS.*包

发送消息的代码

Context context = new InitialContext();
QueueConnectionFactory queueConnectionFactory =`enter code here`
(QueueConnectionFactory) context.lookup("QueueConnectionFactory");
String queueName = "MyQueue";
Queue queue = (Queue) context.lookup(queueName);
queueConnection =
queueConnectionFactory.createQueueConnection() ;
QueueSession queueSession =
queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender queueSender = queueSession.createSender(queue);
TextMessage message = queueSession.createTextMessage();
message.setText("This is a TextMessage");
queueSender.send(message) ;
接收信息的代码

Context context = new InitialContext(); 
QueueConnectionFactory queueConnectionFactory =(QueueConnectionFactory) context.lookup("QueueConnectionFactory"); 
String queueName = "MyQueue";
Queue queue = (Queue) context.lookup(queueName); 
QueueConnection  queueConnection =queueConnectionFactory.createQueueConnection() ;
QueueSession queueSession = queueConnection.createQueueSession (false, •*■ Session.AUTO_ACKNOWLEDGE) ;
QueueReceiver queueReceiver = queueSession.createReceiver(queue);
queueConnection.start() ;
Message message = queueReceiver.receive(1) ;

当iam使用IBM Websphere MQ时,请告诉我如何发送和接收消息。在使用IBM MQ时,IBM是否提供了有助于发送和接收消息的API?

您需要设置JNDI命名服务,为Websphere MQ提供JMS对象。其Websphere MQ实用程序是JMSAdmin。如果您有WebSphereApplicationServer,您也可以使用“WebSphereMQ消息传递提供程序”设置JMS资源(连接工厂和队列或主题)。请注意,Websphere MQ中定义的名称与JNDI名称不同:在设置这些绑定时,您可以选择JNDI名称将引用什么Websphere MQ名称。

您需要设置JNDI命名服务来为Websphere MQ提供JMS对象。其Websphere MQ实用程序是JMSAdmin。如果您有WebSphereApplicationServer,您也可以使用“WebSphereMQ消息传递提供程序”设置JMS资源(连接工厂和队列或主题)。请注意,Websphere MQ中定义的名称与JNDI名称不同:您可以选择在设置这些绑定时JNDI名称将引用的Websphere MQ名称。

检查此答案检查此答案