Search code examples
queuejmsibm-mqwebsphere-liberty

Put JMS message properties in IBM MQ queue and access from other JMS client which run on Websphere liberty


I have two JMS application which use IBM MQ server as a separate MQ server. I want to set message property from one client and put message in IBM queue. Other side client application which run on websphere liberty uses 'messageSelector' to filter and read messages from IBM MQ server according to message property.

Producer code

    public void send(AppMessage msg) throws JMSException {
        MessageProducer messageProducer = this.messageProducer;
        TextMessage sendMsg = session.createTextMessage();
        if (groupingEnabled) {

            sendMsg.setStringProperty(SettingsConstants.JMS_GRP_ID_PROPERTY, msg.getMsgGroupId());
        }
        // Property set in here
        sendMsg.setStringProperty("appServerID","12");
        String message = msg.composeMessage();
        sendMsg.setText(message);
        messageProducer.send(sendMsg);
    }

When I evaluate Message from IBM MQ server side, "appServerID" message property was not visible and messageSelector could not filter message. But "JMSXGroupID" which was set by sendMsg.setStringProperty(SettingsConstants.JMS_GRP_ID_PROPERTY, msg.getMsgGroupId()); was visible and messageSelector was worked.

This is how messageSelector implemented from consumer side

@MessageDriven(activationConfig = {
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "FromPreProcessedQueue"),
        @ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "appServerID = 12")
})
public class ConnectorPreProcessedBean implements MessageListener {

I have tried by adding 'usr' prefix to message property name as in text. I received error message indicating JMS does not support this format.Error : 'The property name 'usr.appServerID' is not a valid Java(tm) identifier'

sendMsg.setStringProperty("usr.appServerID","12");

Then I tried by adding below header field and did not work

MQRFH2 header = new MQRFH2();
header.setFieldValue("appServerID", "12");
sendMsg.setObjectProperty("JMS_IBM_MQRFH2", header);

Message viewed from IBM MQ side

[bin]$ ./amqsbcg FromPreProcessedQueue QM1 1

AMQSBCG0 - starts here
**********************

 MQOPEN - 'FromPreProcessedQueue'


 MQGET of message number 1, CompCode:0 Reason:0
****Message descriptor****

  StrucId  : 'MD  '  Version : 2
  Report   : 0  MsgType : 8
  Expiry   : -1  Feedback : 0
  Encoding : 273  CodedCharSetId : 1208
  Format : 'MQSTR   '
  Priority : 4  Persistence : 1
  MsgId : X'414D5120514D31202020202020202020C49A036602850140'
  CorrelId : X'000000000000000000000000000000000000000000000000'
  BackoutCount : 0
  ReplyToQ       : '                                                '
  ReplyToQMgr    : 'QM1                                             '
  ** Identity Context
  UserIdentifier : 'mqm         '
  AccountingToken :
   X'0000000000000000000000000000000000000000000000000000000000000000'
  ApplIdentityData : '                                '
  ** Origin Context
  PutApplType    : '28'
  PutApplName    : 'WebSphere MQ Client for Java'
  PutDate  : '20240327'    PutTime  : '06213953'
  ApplOriginData : '    '

  GroupId : X'300000000000000000000000000000000000000000000000'
  MsgSeqNumber   : '1'
  Offset         : '0'
  MsgFlags       : '8'
  OriginalLength : '-1'

****Message properties****

  None

****   Message      ****

 length - 33 of 33 bytes

00000000:  1C1C 3232 3432 301C 4446 4958 2049 4E46           '..22420. INF'
00000010:  4F52 4D41 5449 4F4E 2052 4551 5545 5354           'ORMATION REQUEST'
00000020:  1C       

IBM-MQ version: 9.4.3 JMS version: javax.jms from Maven: j2ee:j2ee:1.4 (j2ee-1.4.jar)

Can someone help to resolve this issue by setting custom message properties. Note that this works fine with existing properties in JMS.


Solution

  • For the amqsbcg output, the sample has a third parameter which controls the handling of message properties. Without specifying an option, the default is 0 which is PROPS_AS_Q_DEF. Since your output contains neither the properties section or an RFH2 header, I suspect that means you queue is defined with PROPCTL(NONE). This means that the message is returned to amqsbcg without any properties.

    Try running amqsbcg with 1 as the third parameter and see if you get the properties printed.

    (I know this doesn't answer the original question and should be a comment, but I haven't accumulated enough reputation to make comments, sorry).