MQDestination覆盖记帐令牌值 [英] MQDestination overriding accounting token value

查看:229
本文介绍了MQDestination覆盖记帐令牌值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在系统从入站队列接收到的消息上设置记帐令牌.我正在使用以下方法设置此令牌.

I am trying to set the Accounting Token on the a message which my system received from inbound queue. I am setting this token using the following.

msg.setObjectProperty(JmsConstants.JMS_IBM_MQMD_ACCOUNTINGTOKEN,value)

我的JmsSUpport类中还具有以下属性

Also I have the following properties in my JmsSUpport class

((JmsDestination) dest).setBooleanProperty(WMQConstants.WMQ_MQMD_READ_ENABLED, true);
((JmsDestination) dest).setBooleanProperty(WMQConstants.WMQ_MQMD_WRITE_ENABLED, true);    
((MQDestination) dest).setMQMDWriteEnabled(true);
((MQDestination) dest).setMQMDReadEnabled(true);
((MQDestination) dest).setTargetClient(JMSC.MQJMS_CLIENT_NONJMS_MQ);    

由于出站队列是MQDestination,所以我必须设置以上属性.现在,我观察到我在出站消息上正确设置了值.但是,当另一个应用程序从MQ读取消息时,它具有记帐令牌"的默认值.可能是因为以这种方式配置了MQ以覆盖该值吗?还是因为其他应用程序未正确读取MQ消息?还是我应该使用其他任何属性来启用记帐令牌?

Since the outbound queue is MQDestination I have to set the above properties. Now I am observing that I am correctly setting the value on the outbound message. But when the other application reads the message from the MQ it has default value for Accounting Token. Could this be because the MQ is configured in such way to override the value? Or is it because the other application is not reading MQ message correctly? Or should I be using any other property to enable accounting token?

是因为我正在设置((MQDestination)dest).setTargetClient(JMSC.MQJMS_CLIENT_NONJMS_MQ); msg被剥夺了MQMD标头?

Is it because I am setting ((MQDestination) dest).setTargetClient(JMSC.MQJMS_CLIENT_NONJMS_MQ); the msg gets stripped of MQMD Headers?

推荐答案

不,MQMD不会被剥离.发送消息之前,必须在目标上设置身份上下文.否则,队列管理器将忽略计费令牌.请查看示例代码:

No, MQMD is never stripped off. You have to set identity context on the destination before sending a message. Otherwise queue manager will ignore the Accounting token. Please see the sample code:

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;

import com.ibm.msg.client.jms.JmsConnectionFactory;
import com.ibm.msg.client.jms.JmsFactoryFactory;
import com.ibm.msg.client.jms.JmsDestination;
import com.ibm.msg.client.wmq.WMQConstants;
import com.ibm.msg.client.jms.JmsConstants;
import com.ibm.mq.jms.MQDestination;

public class AccountingTokenDemo {

    public static void main(String[]args) {
        // TODO Auto-generated method stub
        AccountingTokenDemo demo = new AccountingTokenDemo();
        demo.putMessageWithAccountingToken();
    }
       public void putMessageWithAccountingToken() {
            JmsConnectionFactory cf = null;
            Connection connection = null;
            Session session = null;
            Destination reqQ = null;
            MessageProducer producer = null;

            try {               
              // Create a connection factory
              JmsFactoryFactory ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER);
              cf = ff.createConnectionFactory();

              // Set the properties
              cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_BINDINGS);
              cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, "QM2");

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

              // Create a 32 byte accounting toke
              byte [] accountingToken = new byte[32];
              byte b = 'a';
              for(int i=0; i < 32;i++)
                accountingToken[i] = b++;

              // Create destination to send requests
              reqQ = session.createQueue("queue:///REQUESTQ");
              ((MQDestination) reqQ).setTargetClient(WMQConstants.WMQ_CLIENT_NONJMS_MQ);              
              ((JmsDestination) reqQ).setBooleanProperty(WMQConstants.WMQ_MQMD_READ_ENABLED, true);
              ((JmsDestination) reqQ).setBooleanProperty(WMQConstants.WMQ_MQMD_WRITE_ENABLED, true);    
              ((MQDestination) reqQ).setMQMDMessageContext(WMQConstants.WMQ_MDCTX_SET_IDENTITY_CONTEXT);

              // Create producer
              producer = session.createProducer(reqQ);

              // Create a request message
              Message requestMessage = session.createTextMessage("Setting Accounting token on message");
              requestMessage.setObjectProperty(JmsConstants.JMS_IBM_MQMD_ACCOUNTINGTOKEN, accountingToken);
              // Send it off
              producer.send(requestMessage);

            }catch(Exception ex){
                System.out.println(ex);
            }
       }       
}

这篇关于MQDestination覆盖记帐令牌值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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