我正在尝试发布并使用camel将消息发送到远程WMQ。有2个队列,即请求和响应队列。我可以使用我的骆驼路线发布到Response Queue。但是有些标题需要设置为发布到请求队列。 发布到Request Queue时我遇到了问题。
我有一个java代码的工作副本,它能够发布到两个队列并获取数据。但我需要我的骆驼路线来做到这一点。
这里我附上了java(Working)和camel one的代码片段。 有人可以帮助我这对我有很大的帮助。
是否必须设置 MQPutMessageOptions pmo = new MQPutMessageOptions();
和
int openOptions = MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_OUTPUT + MQC.MQOO_SET_IDENTITY_CONTEXT;
如果是,如何使用camel设置这些参数。
如下面的代码所示?
java代码
public class GskMQMessage extends MQMessage
public void connect() {
MQException.log = null;
int openOptions = 0;
try {
Hashtable mqKeyValueProps = new Hashtable();
//com.ibm.mq.constants.CMQC
mqKeyValueProps.put(CMQC.HOST_NAME_PROPERTY, hostName);
mqKeyValueProps.put(CMQC.PORT_PROPERTY, portNo);
mqKeyValueProps.put(CMQC.CHANNEL_PROPERTY, channelName);
if (queueMgr_ == null) {
queueMgr_ = new MQQueueManager(queueMgrName_, mqKeyValueProps);
}
mqTime = System.currentTimeMillis();
if (sendQueue == null) {
openOptions = MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_OUTPUT + MQC.MQOO_SET_IDENTITY_CONTEXT;
sendQueue = queueMgr_.accessQueue(sendQueueName_, openOptions);
}
if (this.sendMqMessage_ == null) {
this.sendMqMessage_ = new GskMQMessage();
}
}
} catch (MQException mqEx) {
mqEx.printStackTrace();
}
public String mqPut(String callPhase, byte[] byteControlHeader, String sendMessageText) {
long mqTime = 0;
String recvData = "";
this.sendMqMessage_.characterSet = 943;
this.sendMqMessage_.expiry = 300;
this.sendMqMessage_.persistence = MQC.MQPER_NOT_PERSISTENT;
this.sendMqMessage_.correlationId = MQC.MQCI_NONE;
byte[] byteApplIdData = //32 byte id
this.sendMqMessage_.applicationIdData = new String(byteApplIdData);
this.sendMqMessage_.messageId[i] = //24 byte id
MQPutMessageOptions pmo = new MQPutMessageOptions();
pmo.options = MQC.MQPMO_FAIL_IF_QUIESCING + MQC.MQPMO_SET_IDENTITY_CONTEXT;
this.sendMqMessage_.clearMessage();
//write to MQMessage.
this.sendMqMessage_.write(byteControlHeader);
this.sendMqMessage_.write(sendMessageText.getBytes(System.getProperty("file.encoding")));
mqTime = System.currentTimeMillis();
//put message to WMQ
this.sendQueue_.put(this.sendMqMessage_, pmo);
}
骆驼代码:
无法发布到请求队列即使在代码中设置了标题。请告诉我以下代码中的问题。
public void process(Exchange exchange) throws Exception {
Message message = exchange.getIn();
String wmqHost = (String) message.getHeader(HOST);
int mqPort = Integer.parseInt((String) message.getHeader(PORT));
String queueMngr = (String) message.getHeader(QUEUE_MNGR);
String channel = (String) message.getHeader(CHANNEL);
String sendQueue = (String) message.getHeader(SEND_QUEUE);
String receiveQueue = (String) message.getHeader(RECEIVE_QUEUE);
String connName = queueMngr + channel;
//setting IBM MQ Specific Headers
message.setHeader(JmsConstants.JMS_IBM_MQMD_APPLIDENTITYDATA,
appIdententyData());
message.setHeader(JmsConstants.JMS_IBM_MQMD_MSGID, createMsgId());
message.setHeader(JmsConstants.JMS_IBM_MQMD_CORRELID, MQC.MQCI_NONE);
message.setHeader(JmsConstants.JMS_IBM_MQMD_PERSISTENCE,
MQC.MQPER_NOT_PERSISTENT);
message.setHeader(JmsConstants.JMS_IBM_MQMD_EXPIRY, new Integer("300"));
message.setHeader(JmsConstants.JMS_IBM_MQMD_CODEDCHARSETID,
new Integer("943"));
message.setBody(getSeriesStartBody());
CamelContext camelContext = //getting context;
if (camelContext.getComponent(connName) == null) {
validateWMQParams(wmqHost, mqPort, channel, queueMngr);
camelContext.addComponent(connName, JmsComponent
.jmsComponent(createWMQConnection(wmqHost, mqPort,
queueMngr, channel)));
}
}
//creates connection with wmq
private com.ibm.mq.jms.MQConnectionFactory createWMQConnection(String host,
int port, String queueMngr, String channel) throws JMSException {
MQQueueConnectionFactory mqConnectionFactory = new MQQueueConnectionFactory();
mqConnectionFactory.setHostName(host);
mqConnectionFactory.setPort(port);
mqConnectionFactory.setQueueManager(queueMngr);
mqConnectionFactory.setChannel(channel);
mqConnectionFactory.setTransportType(1);
return mqConnectionFactory;
}