简体   繁体   English

我们可以将我的Java-Spring-mvc服务连接到IBM MQ而不用从队列中生成或使用绑定文件吗?

[英]can we connect my Java-Spring-mvc service to IBM MQ without generating or using binding files from the queues

in my service(built on java8 - springMVC - IBM MQ) we are generating binding file from IBM MQ and and using that binding file to connect to queues and my service. 在我的服务(基于java8-springMVC-IBM MQ构建)中,我们从IBM MQ生成绑定文件,并使用该绑定文件连接到队列和我的服务。 is there any way i could connect with the queue without using that binding file. 有什么方法可以不使用该绑定文件而与队列连接。

The reason is my service is talking with 10 queues and for every queue i have to generate binding file and put them all in one file and use it and we have dev, qa, prod environments so binding files change for each of them and this is big pain. 原因是我的服务正在处理10个队列,对于每个队列,我必须生成绑定文件并将其全部放入一个文件中并使用它,并且我们拥有dev,qa,prod环境,因此每个绑定文件都将更改,这是大痛苦。

so is there a way to connect queues without the binding files and possible please attach the code or any reference! 因此,有一种无需绑定文件即可连接队列的方法,请附加代码或任何参考!

You can use below code with IBM MQ jars.




import com.ibm.mq.MQEnvironment;
import com.ibm.mq.MQException;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;

public class Test {

    public static void main(String[] args) {
            MQEnvironment.hostname = queue_manager_ip;
            MQEnvironment.port = queue_manager_port;
            MQEnvironment.channel = channel_name;
            MQEnvironment.disableTracing();

            MQQueueManager mqmanager = null;
            MQQueue mqueue = null;

            try {
                mqmanager = new MQQueueManager(" ");
                int i = 8226;

                mqueue = mqmanager.accessQueue(queue_name, i);
            } catch (MQException localMQException) {
                System.out.println(localMQException.getMessage());
            }
            String str1 = "";
            String str2 = "";

            MQGetMessageOptions localMQGetMessageOptions = new MQGetMessageOptions();
            localMQGetMessageOptions.options = 8192;

            MQMessage localMQMessage = new MQMessage();
            mqueue.get(localMQMessage, localMQGetMessageOptions);
            byte[] arrayOfByte = new byte[localMQMessage.getTotalMessageLength()];
            localMQMessage.readFully(arrayOfByte);
            str1 = new String(arrayOfByte);
            System.out.println(str1);
    }

}

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

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