有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java IBM JMS MQ在MQM头中添加用户ID

如何在IBM JMS MQ中的MQM头中设置userID,默认值为“MQM”,我需要在发送消息时将其设置为不同的userID。我正在使用com。国际商用机器公司mqjms jar和应用程序部署在Tomcat上


共 (1) 个答案

  1. # 1 楼答案

    在应用程序中,您需要访问JMS规范之外的一些IBM MQ功能

    IBM MQ v8知识中心在页面“Reading and writing the message descriptor from an IBM MQ classes for JMS application”中说明了如何使用IBM MQ类为JMS设置MQMD属性

    You must set the Destination object property WMQ_MQMD_WRITE_ENABLED to true for the setting of MQMD properties to have any effect. You can then use the property setting methods of the message (for example setStringProperty) to assign values to the MQMD fields. All MQMD fields are exposed except StrucId and Version; BackoutCount can be read but not written to.

    This example results in a message being put to a queue or topic with MQMD.UserIdentifier set to "JoeBloggs". // Create a ConnectionFactory, connection, session, producer, message // ...

    // Create a destination
    // ...
    
    // Enable MQMD write
    dest.setBooleanProperty(WMQConstants.WMQ_MQMD_WRITE_ENABLED, true);
    
    // Optionally, set a message context if applicable for this MD field
    dest.setIntProperty(WMQConstants.WMQ_MQMD_MESSAGE_CONTEXT, 
      WMQConstants.WMQ_MDCTX_SET_IDENTITY_CONTEXT);
    
    // On the message, set property to provide custom UserId
    msg.setStringProperty("JMS_IBM_MQMD_UserIdentifier", "JoeBloggs");
    
    // Send the message
    // ...
    

    为了使用WMQ_MDCTX_SET_IDENTITY_CONTEXT,您需要向连接到IBM MQ队列管理器的用户授予OAMqmgr对象和消息将queuequeue对象和queue上的PUT权限+setid,以及您将授予的任何正常权限(例如:qmgr或{}上的+put