我正在尝试使用现有的 Mule 代码发送消息。已经编写了一些代码,但由于某种原因,据我所知,有一个轴“错误”。
然后使用JMSEndpoint调用“call”方法发送消息并等待响应。这是我的代码:
String payload = eventContext.getMessage().getPayloadAsString();
JmsConnector amqConnector = (JmsConnector) eventContext.getMuleContext().getRegistry().lookupConnector("Active_MQ");
JMSVendorAdapter adapter = JMSVendorAdapterFactory.getJMSVendorAdapter();
QueueConnector connector = new QueueConnector(amqConnector.getConnectionFactory(), 1, 1, 2000, 2000, 60000, true, null, null, null, adapter, null);
Connection connection = connector.getConnectionFactory().createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("ExampleQueue");
JMSEndpoint endpoint = connector.createEndpoint(queue);
connector.start();
// Byte byteMessage = new Byte(payload);
// BytesMessage mess = session.createBytesMessage();
// mess.writeByte(byteMessage);
byte[] response = endpoint.call(payload.getBytes("UTF-8"), 10000);
return response.toString();
该方法本身要求一个 byte[],所以我给它一个带有 UTF-8 字符集的 byte[]。 但它抛出了这个错误:
org.apache.axis.transport.jms.InvokeException: Error: unexpected message type received - expected BytesMessage
在 JMSConnector 类中,它在此 block 中失败:
BytesMessage response = null;
try {
response = (BytesMessage)subscriber.receive(timeout);
} catch (ClassCastException cce) {
throw new InvokeException
("Error: unexpected message type received - expected BytesMessage");
}
有一个关于此问题的开票,他们称之为“错误”???所以它有点像抛出 ClassCastException !不敢相信这是真的!有办法解决这个问题吗???那么 Mule 是怎么做到的呢?
如何实现像 Mule 在其组件中那样将 JMS 消息发送到队列?
谢谢。
最佳答案
Mule 使用 org.mule.transport.jms.JmsMessageDispatcher 将消息分派(dispatch)到 JMS 目的地
关于java - Mule 使用什么类来发送 JMS 消息(端点),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18514023/