0 Replies Latest reply on Jun 13, 2019 4:52 PM by Hillol Pal

    Alternative JMS message is not getting posted in the Queue

    Hillol Pal Newbie

      In a custom application we have created a Queue and tried to post messages to test the configuration.

       

      Surprisingly it is observed that that every alternative message is not getting posted in the Queue when inquired through Queue Browser or JBOSS console.

       

      We are in EAP 6.4 and following is the queue configuration in jboss.domain.xml

       

       

      <jms-queue name="NRMSyncQueue">

      <entry name="java:/jms/queue/NRMSyncQueue"/>

      <entry name="java:jboss/exported/jms/queue/NRMSyncQueue"/>

      <durable>true</durable>

      </jms-queue>

       

       

       

      <address-setting match="jms.queue.NRMSyncQueue">

      <dead-letter-address>jms.queue.NRMSyncErrorQueue</dead-letter-address>

      <expiry-address>jms.queue.NRMSyncExpiryQueue</expiry-address>

      <redelivery-delay>1000</redelivery-delay>

      <max-delivery-attempts>4</max-delivery-attempts>

      <max-size-bytes>10485760</max-size-bytes>

      <address-full-policy>BLOCK</address-full-policy>

      <message-counter-history-day-limit>10</message-counter-history-day-limit>

      <redistribution-delay>1000</redistribution-delay>

      </address-setting>

       

      Following is the sample code snippet to send the message to the queue:

       

      <br>

      public void publish(Notification notification, ContextInfo contextInfo,

      ConfigurationPropertiesInfo configurationPropertiesInfo) throws NotificationPublishException {

       

      QueueConnectionFactory queueConnectionFactory = null;

      QueueConnection queueConnection = null;

      QueueSession queueSession = null;

      MessageProducer messageProducer = null;

       

      JmsUtil jmsUtil = new JmsUtil();

       

      try {

       

      final Context context = jmsUtil.getInitialContext(configurationPropertiesInfo);

       

      queueConnectionFactory =

      (QueueConnectionFactory) context.lookup(configurationPropertiesInfo.getRemoteConnectionFactory());

       

      queueConnection = queueConnectionFactory.createQueueConnection();

      queueConnection.start();

      queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

       

      Queue queue = (Queue) context.lookup(configurationPropertiesInfo.getNrmSyncQueueName());

      messageProducer = queueSession.createProducer(queue);

       

      TextMessage textMessage = queueSession.createTextMessage();

       

        textMessage.setJMSCorrelationID(notification.getCorrelationId());

      textMessage.setStringProperty("TIMESTAMP", notification.getCreatedWhen()); // setTimeStamp accepts long argument

        textMessage.setText(notification.getNotificationData());

       

      messageProducer.send(textMessage);

       

      LOGGER.info("Published Message : JMSCorrelationID : {}, TimeStamp : {}, MessageText : {}",

      textMessage.getJMSCorrelationID(), textMessage.getStringProperty("TIMESTAMP"), textMessage.getText());

       

      } catch (Exception e) {

      LOGGER.error("Exception ocurred during publish : {}", e);

      NotificationPublishException exp = new NotificationPublishException(e);

        exp.setErrorCode(NotificationConstants.EAI_NRMSYNC_002);

      throw exp;

      } finally {

      jmsUtil.closeJmsResources(messageProducer, null, queueSession, queueConnection);

      }

      }

      }

       

      </br>