简体   繁体   English

在IBM MQ Lite中推送消息时发生错误

[英]Error is occurred while pushing the Message in IBM MQ Lite

I am using IBM MQ Light. 我正在使用IBM MQ Light。

I am trying to push a message in IBM MQ Lite through java program, My Connection is well and good. 我正在尝试通过java程序在IBM MQ Lite中推送消息,“我的连接”很好。 When i run the program and check the Localhost it shows me that client is connected but after 3-4 seconds it is disconnected and Exception is thrown at console. 当我运行程序并检查Localhost时,它向我显示客户端已连接,但在3-4秒后它已断开连接,并在控制台上引发了异常。

Following is my error log: 以下是我的错误日志:

Problem with subscribe request: amqp:unauthorized-access: AMQXR0042E: A subscribe request was not authorized for channel PlainText received from 127.0.0.1. AMQXR0004E: MQSeries verb=SPISubscribe(String) returned cc=2(int) MQCC_FAILED rc=2035(int) MQRC_NOT_AUTHORIZED

A 2035 error code means you are not authorized. 2035错误代码表示您无权。 You may need to get more info to determine why your client is failing. 您可能需要获取更多信息,以确定客户端失败的原因。 You could use the MQS_REPORT_NOAUTH or MQSAUTHERRORS setting to get more info about the authority failure and what access is failing. 您可以使用MQS_REPORT_NOAUTHMQSAUTHERRORS设置来获取有关授权失败和访问失败的更多信息。

I have a sample code by which you can push the message in IBM MQ Lite 我有一个示例代码,您可以通过该示例代码在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

Try it , It works in my case 试试看,对我来说有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM