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

发布于 2024-12-01 21:51:27 字数 1676 浏览 0 评论 0原文

可能的重复:
使用 JMS 连接到 IBM MQ

我知道 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) ;

代码请让我知道当我使用 IBM Websphere MQ 时如何发送和接收消息。 IBM 是否提供任何 API 来帮助在使用 IBM MQ 时发送和接收消息?

Possible Duplicate:
Using JMS to connect to IBM MQ

I know that JMS is a messaging standard provided by sun and IBM Websphere MQ is an implementation of JMS.

I have always used JMS and never used MQ. So i have a couple of questions.

Using JMS I will configure the connection factory and the queues in the application server and use the below code to send and receive messages. In JMS we use the javax.jms.* package.

Code for sending message

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) ;

Code for receiving 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) ;

Please let me know how i can send the receive the messages when iam using IBM Websphere MQ. Does IBM provide any API which help in sending and receiving the messages when IBM MQ is being used?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无声静候 2024-12-08 21:51:27

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

You need to set up a JNDI naming service to provide your JMS objects for Websphere MQ. The Websphere MQ utility for that is JMSAdmin. If you've got Websphere Application Server, you can alternatively set up JMS resources (connection factory and queues or topics) using 'Websphere MQ messaging provider'. Note that the names defined in Websphere MQ are not the same as JNDI names: you choose whan JNDI name will refer to what Websphere MQ name when setting up these bindings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文