如何在IBM MQ Light中使用示例应用程序

时间:2016-06-20 05:27:08

标签: java ibm-mq amqp

我正在尝试发送消息以及接收消息给IBM MQ lite,我在c盘上提取了mqlight-developer-1.0.2.0-L151130.2mqlight-distribution-1.0.2016020300。我也下载了所需的jar     Google Gson 2.2.4,     Logback 1.1.2,     Apache Netty 4.0.21.Final,     Stateless4J 2.5.0,     SLF4J 1.7.5     Commons SSL 0.3.11     com.ibm.mqlight

我启动了Mq Light并且UI出现了, 为了运行helloWorld程序,我遇到了一些困难。我怎么能这样做

1 个答案:

答案 0 :(得分:0)

使用此代码,它将在IBM MQ lite

中推送消息
package com.Queue;
import com.ibm.mqlight.api.ClientOptions;

import com.ibm.mqlight.api.Delivery;
import com.ibm.mqlight.api.DestinationAdapter;
import com.ibm.mqlight.api.NonBlockingClient;
import com.ibm.mqlight.api.NonBlockingClientAdapter;
import com.ibm.mqlight.api.StringDelivery;


public class SendReceive2 
{
    public static void main(String[] cmdline) 
    {
        ClientOptions clientOpts = ClientOptions.builder().setCredentials("ad", "jms123").build();



        NonBlockingClient.create("amqp://localhost", clientOpts, new NonBlockingClientAdapter<Void>()
        {

            public void onStarted(NonBlockingClient client, Void context) 
            {
                client.subscribe("JmsQueue",  new DestinationAdapter<Void>() 
                {
                    public void onMessage(NonBlockingClient client, Void context, Delivery delivery) 
                    {
                        if (delivery.getType() == Delivery.Type.STRING)
                            System.out.println(((StringDelivery)delivery).getData());
                    }
                }, null, null);
            }
        }, null);





        NonBlockingClient.create("amqp://localhost", clientOpts, new NonBlockingClientAdapter<Void>()
        {
            public void onStarted(NonBlockingClient client, Void context) 
            {
                client.send("JmsQueue", "Jms Queue is Formed!", null);
            }

        }, null);






    }//main


}//class