如何使用Java API设置消息选择器? [英] How do you set a message selector using Java API?

查看:82
本文介绍了如何使用Java API设置消息选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个简单的测试用例,以基于message属性从队列中提取消息,达到7.5.0.3 QMgr并使用7.5.0.3客户端jar.

I'm trying to write a simple test case to pull messages from a queue based on a message property, hitting a 7.5.0.3 QMgr and using the 7.5.0.3 client jars.

我在网上看到的所有内容都表明,打开队列时需要指定消息选择器.我对此表示满意,但我只看到两种打开方法:

Everything I have seen online says that I need to specify the message selector when I open the queue. I'm fine with that, but I only see two ways to open it:

MQQueueManager.accessQueue(
    String queueName, 
    int openOptions);

MQQueueManager.accessQueue(
    String queueName, 
    int openOptions, 
    String queueMgr, 
    String dynamicQueueName, 
    String altUserId);

这些都不允许我指定消息选择器.我是从命令行批处理应用程序运行的,而不是在应用程序服务器中运行的,因此无法使用JMS选择器.

Neither of these allow me to specify a message selector. I'm running this from a command line batch application, not in an app server, so using JMS selectors is not possible.

这是有关选择器的IBM文档: WebSphere MQ消息选择器,它表明选择必须作为MQOPEN调用的一部分进行.

Here is the IBM documentation on selectors: WebSphere MQ Message Selectors which shows that selection must happen as part of the MQOPEN call.

推荐答案

MQ JMS API提供了您正在寻找的消息选择语法类型.基本的MQ Java API提供了基于MessageId和CorrelationId的消息选择,并且还没有提供您正在寻找的类型选择语法.您提供的文档链接是针对MQ C API的.

MQ JMS API provides the type of message selection syntax you are looking for. The base MQ Java API provides message selection based on MessageId and CorrelationId and it does not yet provide type selection syntax you are looking for. The documentation link you provided is for MQ C API.

使用MQ JMS API,可以如下所示进行消息选择:

Using MQ JMS API, message selection can be done as shown here:

      // Create JMS objects
      connection = cf.createConnection();
      session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

      // Create queue destination 
      Destination queDest= session.createQueue(que);

      // Create consumer with selector
      String selector = "category='bucket1'";         
      MessageConsumer cons= session.createConsumer(queDest, selector);

      connection.start();
      // receive messages
      Message inMessage = cons.receive(5000);

这篇关于如何使用Java API设置消息选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆