简体   繁体   English

从目标名称Apache Camel + IBM MQ中除去“ queue:///”

[英]Remove “queue:///” from destination name Apache Camel + IBM MQ

Using apache camel I am sending mesasge to IBM Queue Q001IN , but at the other end the application is validating for the destination and they are expecting destination as Q001IN however they are receiving as queue:///Q001IN instead of Q001IN. 我使用apache骆驼将消息发送给IBM Queue Q001IN ,但是在另一端,应用程序正在为目的地进行验证,他们期望目的地为Q001IN但是他们以queue:/// Q001IN而不是Q001IN的形式接收。

...
.to("jms:Q001IN")
.end()

Is there anyway I can override this to remove queue:/// ? 无论如何,我可以覆盖它以删除queue:///吗?

I tried below but it does not work. 我在下面尝试过,但是没有用。

.setHeader("destination", simple("QUEUE_NAME"))
.setHeader("destinationName", simple("QUEUE_NAME"))
.to("jms:Q001IN")

Your receiver application receives a JMS Destination object, a JMS Queue , to be exact. 确切地说,您的接收方应用程序会收到一个JMS目标对象JMS Queue What you see as "queue:///" is the toString() of that object. 您看到的“ queue:///”是该对象的toString()。 If you want to get to the queue name, you must (unfortunately), cast the destination object to javax.jms.Queue and then use method Queue.getQueueName() . 如果要获取队列名称,则必须(不幸地)必须将目标对象转换为javax.jms.Queue ,然后使用方法Queue.getQueueName() I'm not sure about your receiving application, but let's say dest contains the JMSDestination of your received Message: 我不确定您的接收应用程序,但可以说dest包含您接收到的消息的JMSDestination:

import javax.jms.Queue
Queue q = (Queue)dest;
String qName = q.getQueueName();

I think the other applications are using IBM MQ Specific API and Headers. 我认为其他应用程序正在使用IBM MQ特定API和标头。 That's the reason they are able to retrieve only queue name. 这就是他们只能检索队列名称的原因。 If i send message using below they are able to receive queue name without queue:/// 如果我使用下面的方法发送消息,他们将能够接收没有队列的队列名称:///

    Hashtable<String, Object> properties = new Hashtable<String, Object>();
    properties.put(MQConstants.HOST_NAME_PROPERTY, HOST);
    properties.put(MQConstants.PORT_PROPERTY, new Integer(PORT));
    properties.put(MQConstants.CHANNEL_PROPERTY, CHANNEL);
    MQQueueManager queueManager = new MQQueueManager(QUEUE_MANAGER, properties);
    int openOptions = MQConstants.MQOO_INPUT_AS_Q_DEF | MQConstants.MQOO_OUTPUT;
    com.ibm.mq.MQQueue ibmQueue = queueManager.accessQueue(QUEUE_NAME, openOptions);
    MQMessage msg = new MQMessage();
    MQRFH2 rfh2 = new MQRFH2();
    rfh2.setFieldValue("mcd", "Msd", "jms_text");
    rfh2.setFieldValue("jms", "Dst", QUEUE_NAME);
    rfh2.write(msg);
    msg.writeString("This is using IBM API : " + System.currentTimeMillis() % 1000);
    msg.format = CMQC.MQFMT_RF_HEADER_2;
    MQPutMessageOptions pmo = new MQPutMessageOptions();
    ibmQueue.put(msg, pmo);

And even if i use JMS API as below. 即使我使用JMS API如下。

        JmsFactoryFactory ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER);
        JmsConnectionFactory cf = ff.createConnectionFactory();
        cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, HOST);
        cf.setIntProperty(WMQConstants.WMQ_PORT, PORT);
        cf.setStringProperty(WMQConstants.WMQ_CHANNEL, CHANNEL);
        cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
        cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, QUEUE_MANAGER);
        cf.setStringProperty(WMQConstants.WMQ_APPLICATIONNAME, "JmsPutGet (JMS)");
        cf.setBooleanProperty(WMQConstants.USER_AUTHENTICATION_MQCSP, true);
        cf.setStringProperty(WMQConstants.USERID, APP_USER);
        JMSContext context = cf.createContext();
        Queue destination = context.createQueue(QUEUE_NAME);

        TextMessage message = context.createTextMessage("This is using JMS API" + System.currentTimeMillis() % 1000);
        JMSProducer producer = context.createProducer();
        producer.send(destination, message);
        System.out.println("Sent message:\n" + message);
        System.out.println("JMSDestination : " + ((Queue) message.getJMSDestination()).getQueueName());

and try to case destination to queue and get the queue name i am getting 并尝试将目的地排队以获取我正在获得的队列名称

queue:///<Queue_Name>

Below is the output 下面是输出

This is using JMS API456
JMSDestination : queue:///<Queue_Name>

When i was trying to browse both message one sent using jms and other using ibm mq 当我尝试浏览使用JMS发送的消息和使用ibm mq发送的其他消息时

The destination is different for both as shown below. 两者的目的地不同,如下所示。

在此处输入图片说明

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

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