[V9.0.4 Oct 2017]

Running the IBM MQ Bridge to blockchain client sample

You can use the JMS client sample that is provided with the IBM® MQ Bridge to blockchain, to put a message on the input queue that the blockchain bridge is checking and see the reply that is received.

Before you begin

Your IBM MQ Bridge to blockchain is running and is connected to your IBM MQ Advanced queue manager and your blockchain network, and is ready to process input messages.

About this task

Find the JMS sample application in the samp directory of the IBM MQ Bridge to blockchain.

Procedure

  1. Edit the client sample Java source file.
    Follow the instructions in the sample to configure it to match your IBM MQ environment and your blockchain network. The following code from the sample defines the JSON request message to send to the bridge:
    
          // Create the JSON request message.
          // Modify "query", "exampleBlockchainChannelName", and "exampleChaincodeName" to
          // match your deployed blockchain chaincode.
          // The "operation" field is optional, but recommended. It should be set to QUERY
          // or UPDATE to match what the chaincode is going to do.
    
         JSONObject inputMsg = new JSONObject();
          inputMsg.put("operation", "QUERY");
    
         inputMsg.put("function", "query");
          inputMsg.put("channel", "exampleBlockchainChannelName");
          inputMsg.put("chaincodeName","exampleChaincodeName");
    
    
         // Create the JSON arguments for the request message.
          // Modify "a" to match your deployed blockchain chaincode
          // requirements, and add further arguments as necessary
    
         JSONArray myArgs = new JSONArray();
          myArgs.add("a");
          inputMsg.put("args", myArgs);
    
    
          TextMessage message = session.createTextMessage(inputMsg.serialize());
          message.setJMSReplyTo(replyToQueue);
    
    
  2. Compile the sample.
    Point to the IBM MQ client classes and JSON4j.jar file that is shipped in the bridge directory.
    javac -cp $MQ_JAVA_INSTALL_PATH/lib/*:../prereqs/JSON4J.jar SimpleBCBClient.java
  3. Run the compiled class.
    java -cp $MQ_JAVA_INSTALL_PATH/lib/*:../prereqs/JSON4J.jar:. SimpleBCBClient
    
    Starting Simple MQ Blockchain Bridge Client
    Created the message. Starting the connection
    Sent message:
    
     JMSMessage class: jms_text
      JMSType:          null
      JMSDeliveryMode:  2
      JMSDeliveryDelay: 0
      JMSDeliveryTime:  1508427559117
      JMSExpiration:    0
      JMSPriority:      4
      JMSMessageID:     ID:414d5120424342514d202020202020209063e859ea36aa24
      JMSTimestamp:     1508427559117
      JMSCorrelationID: null
      JMSDestination:   queue:///APPL1.BLOCKCHAIN.INPUT.QUEUE
      JMSReplyTo:       queue:///APPL1.BLOCKCHAIN.REPLY.QUEUE
      JMSRedelivered:   false
        JMSXAppID: java                        
       JMSXDeliveryCount: 0
        JMSXUserID: USER1    
       JMS_IBM_PutApplType: 6
        JMS_IBM_PutDate: 20171019
        JMS_IBM_PutTime: 15391912
    {"args":["a"],"function":"query","channel":"exampleBlockchainChannelName","operation":"QUERY","chaincodeName":"exampleChaincodeName"}
    Response message:
    
      JMSMessage class: jms_text
      JMSType:          null
      JMSDeliveryMode:  1
      JMSDeliveryDelay: 0
      JMSDeliveryTime:  0
      JMSExpiration:    0
      JMSPriority:      4
      JMSMessageID:     ID:c3e2d840e2e2f0f84040404040404040d2afa27229838af2 
      JMSTimestamp:     1497439784000
      JMSCorrelationID: ID:414d5120424342514d202020202020209063e859ea36aa24  *(JMSMessageID of the input message)
      JMSDestination:   null
      JMSReplyTo:       null
      JMSRedelivered:   false
        JMSXAppID: java                    
        JMSXDeliveryCount: 1
        JMSXUserID: USER1        
        JMS_IBM_Character_Set: UTF-8
        JMS_IBM_Encoding: 273
        JMS_IBM_Format: MQSTR   
        JMS_IBM_MsgType: 8
        JMS_IBM_PutApplType: 2
        JMS_IBM_PutDate: 20171019
        JMS_IBM_PutTime: 15392014
    {
       "data": "20",
       "message": "OK",
       "statusCode": 200,
       "statusType": "SUCCESS"
    }
    Response text: 
    {
       "data": "20",
       "message": "OK",
       "statusCode": 200,
       "statusType": "SUCCESS"
    }
    SUCCESS
    

    If the client receives a timeout error waiting for the response, check that the bridge is running.