Я создал две очереди на сервере WildFly 12 для отправки и получения.
При отправке сообщения я не получаю messageId, полезную нагрузку и некоторые другие свойства.
При отправке сообщения яполучен объект сообщения, как показано ниже в журнале.
Sent message:\n [ActiveMQMessage[ID:8b059348-2abb-11e9-9328-cf63907a777c]:PERSISTENT/ClientMessage[messageID=0, durable=true, address=jms.queue.SENDING,userID=8b059348-2abb-11e9-9328-cf63907a777c,properties=TypedProperties[__AMQ_CID=88dce6e5-2abb-11e9-9328-cf63907a777c,JMSReplyTo=jms.queue.RECEIVING,JMSCorrelationID=ad6f0b76-e484-4cde-9020-f33c628e14db]]]
При получении сообщения из очереди «ПРИЕМ» я получаю нулевой объект.
Ниже приведена конфигурация моей очереди.
<subsystem xmlns="urn:jboss:domain:messaging-activemq:3.0">
<server name="default">
<security-setting name="#">
<role name="guest" send="true" consume="true" create-non-durable-queue="true" delete-non-durable-queue="true"/>
</security-setting>
<address-setting name="#" dead-letter-address="jms.queue.DLQ" expiry-address="jms.queue.ExpiryQueue" max-size-bytes="10485760" page-size-bytes="2097152" message-counter-history-day-limit="10"/>
<http-connector name="http-connector" socket-binding="http" endpoint="http-acceptor"/>
<http-connector name="http-connector-throughput" socket-binding="http" endpoint="http-acceptor-throughput">
<param name="batch-delay" value="50"/>
</http-connector>
<remote-connector name="remote-artemis" socket-binding="remote-artemis"/>
<in-vm-connector name="in-vm" server-id="0"/>
<http-acceptor name="http-acceptor" http-listener="default"/>
<http-acceptor name="http-acceptor-throughput" http-listener="default">
<param name="batch-delay" value="50"/>
<param name="direct-deliver" value="false"/>
</http-acceptor>
<in-vm-acceptor name="in-vm" server-id="0"/>
<jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>
<jms-queue name="SENDING" entries="queue/SENDING java:jboss/exported/jms/queue/SENDING"/>
<jms-queue name="RECEIVING" entries="queue/RECEIVING java:jboss/exported/jms/queue/RECEIVING"/>
<jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>
<connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>
<connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector"/>
<pooled-connection-factory name="activemq-ra" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm" transaction="xa"/>
<pooled-connection-factory name="remote-artemis" entries="java:/jms/remoteCF java:jboss/exported/jms/remoteCF" connectors="remote-artemis" user="user123" password="Password123"/>
</server>
</subsystem>
Я создал одну службу WSDL для отправки и получения сообщений.
Ниже приведен мой Java-код для подключения.
public void connect() throws JMSException {
// Set up the namingContext for the JNDI lookup
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
env.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:10010");
env.put(Context.SECURITY_PRINCIPAL, "username");
env.put(Context.SECURITY_CREDENTIALS, "password");
try {
namingContext = new InitialContext(env);
connectionFactory = (ConnectionFactory) namingContext.lookup(CONNECTION_FACTORY);
connection = connectionFactory.createConnection("username", "password");
connection.start();
logger.debug("Connected.");
} catch (NamingException e) {
e.printStackTrace();
}
System.out.println("Got ConnectionFactory " + CONNECTION_FACTORY);
}
Для отправки и получения сообщений, созданных по методу, указанному ниже.
public byte[] sendAndRecieve(String driver) throws JMSException, TimeoutException {
Session session = connection.createSession(false, 1);
// Message send code start
Queue requestQueue = session.createQueue(requestQueueName);
Queue responseQueue = session.createQueue(responseQueueName);
String correlationId = UUID.randomUUID().toString();
MessageProducer sender = session.createProducer(requestQueue);
TextMessage message = (TextMessage) session.createTextMessage(driver);
message.setJMSMessageID("ID:" + System.currentTimeMillis());
message.setJMSDeliveryMode(2);
message.setJMSExpiration(0);
message.setJMSPriority(4);
message.setJMSTimestamp(System.currentTimeMillis());
message.setJMSDestination(requestQueue);
message.setJMSRedelivered(false);
message.setJMSCorrelationID(correlationId);
message.setJMSReplyTo(responseQueue);
message.setText(driver);
sender.send(message);
logger.info("Sent message:\\n [{}]", message);
String selector = "JMSCorrelationID = '" + correlationId + "'";
MessageConsumer receiver = session.createConsumer(responseQueue, selector);
byte[] byteArray = null;
logger.debug("Recieving response...");
Message receivedMessage = receiver.receive(50000);
logger.debug("Response recieved: [{}]", receivedMessage);
if ((receivedMessage instanceof ObjectMessage)) {
ObjectMessage objMessage = (ObjectMessage) receivedMessage;
byteArray = (byte[]) objMessage.getObject();
if (byteArray != null) {
logger.debug("Its size is {} bytes", Integer.valueOf(byteArray.length));
} else {
logger.error("Received message's content is null");
byteArray = null;
}
} else {
if (receivedMessage == null) {
logger.error("Received message is null");
sender.close();
receiver.close();
session.close();
throw new TimeoutException("Failed to compose document");
}
logger.error("Received unsupported message type [{}]", receivedMessage.getClass().toString());
byteArray = null;
}
sender.close();
receiver.close();
session.close();
return byteArray;
}
Благодарим Вас за помощь.