0

I created two Queue on WildFly 12 server for Sending and Receiving.

While sending a message I am not getting messageId, payload, and some other properties.

While sending a message I received message object as below in log.

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]]]

While receiving a message from "RECEIVING" queue I am getting a null object.

Below is my queue configuration.

<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>

I created one WSDL service to send and receive messages.

Below is my java code for connecting connection.

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);

}

For sending and receiving messages created below method.

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;
}

Appreciate your help.

JoshMc
  • 10,239
  • 2
  • 19
  • 38
paril
  • 1,850
  • 2
  • 14
  • 26
  • If `javax.jms.MessageConsumer.receive()` returns `null` that just means that no message was received. This indicates to me that perhaps the component which is processing the request and providing the response isn't operating as expected. Can you confirm? – Justin Bertram Feb 07 '19 at 18:50
  • Also, the `toString()` implementation in ActiveMQ Artemis for `javax.jms.Message` will not display the payload of the message as it's an opaque byte array as far as the implementation is concerned. – Justin Bertram Feb 07 '19 at 18:54
  • Yes. I want a response from RECEIVING queue. – paril Feb 08 '19 at 03:20
  • 1
    I understand you want a response from the `RECEIVING`, but some code/application has to receive the request message from the `SENDING` queue, process it, and put the response message on the `RECEIVING` queue in order for the code you've pasted here to actually get a response message. Based on the behavior you're describing it doesn't appear that such a process is actually happening. Can you paste the code that is doing this work? – Justin Bertram Feb 08 '19 at 03:26

0 Answers0