11.3 JMS

JMSUtility and TopicUtility is now deprecated.MessageProducerUtilityshould be used for producing messages to JMS destinations. MessageProducerUtility requires entries of the JMS destinations to be present in the table DIGX_FW_DESTINATION_METADATA.

  • For any new as well as existing customized JMS queues or topics, Please ensure to add entries in this table with relevant metadata for topic/queue maintenance. The table has three columns:
    • DESTINATION: The name of the topic or queue.
    • CONNECTION_FACTORY: The connection factory used.
    • DESTINATION_TYPE: The type (e.g., topic or queue).

    For example,

    INSERT INTO DIGX_FW_DESTINATION_METADATA values ('PoliciesTopic','POLICIESQCF', 'TOPIC');
  • Add below dependency to build.gradle of the JMS listener project.
    implementation
            "com.ofss.digx.infra:com.ofss.digx.infra.events:$libs_digxVersion"
  • For message processing logic, create a class implementing com.ofss.digx.infra.events.processor.IMessageProcessor interface, override the process method and call this method from the JMS listener class. Refer Section3: Implementing Event Processing Logicof New Topic Creation With Producer and Consumer chapter for the same.
  • Sample code for JMS listener
    package com.ofss.digx.jms.sms.listener.authorization.policy; 
    import com.ofss.common.platform.server.ServerPlatformUtils;
    import com.ofss.digx.app.sms.dto.authorization.policy.PolicyMapDTO;
    import com.ofss.digx.app.sms.processors.authorization.policy.PoliciesMessageProcessor;
    import com.ofss.digx.infra.jms.listener.IJMSTopicListener;
    import org.slf4j.Logger;import org.slf4j.LoggerFactory; 
    import javax.jms.JMSException;import javax.jms.Message;
    import javax.jms.ObjectMessage;
    import java.io.Serializable; 
    public class PoliciesTopicListener implements IJMSTopicListener 
    {     
    /**     * Stores the name of the entity(class)represented by this {@code Class} object * as a {@code String}     */    
    private static final String THIS_COMPONENT_NAME = PoliciesTopicListener.class.getName();     
    private static final transient Logger logger = LoggerFactory.getLogger(THIS_COMPONENT_NAME);     
    /**     * Property which stores the topic JNDI name.     */    
    private static final String POLICIES_TOPIC = "PoliciesTopic";     
    /**     * Property which stores the topic connection factory JNDI name.     */    
    private static final String POLICIES_QCF = "POLICIESQCF";     
    private final PoliciesMessageProcessor processor = new PoliciesMessageProcessor();     
    @Override    public String getConnectionFactoryName()
              {        
    return getJNDIName(POLICIES_QCF);    
    }     
    @Override public String getTopicName()
            {        
    return getJNDIName(POLICIES_TOPIC);    
    }     
    @Override public void onMessage(Message message)
              {        
    logger.debug("Entered into onMessage() of policy topic listener in class {} ",
            THIS_COMPONENT_NAME);       
     Serializable obj = null;        
    if (message instanceof ObjectMessage) 
    {            
    ObjectMessage objMessage = (ObjectMessage)message;            
    try {                
    obj = objMessage.getObject();                
    if (obj instanceof PolicyMapDTO) 
    {                   
              @SuppressWarnings("unchecked")                   
              PolicyMapDTO applicationRoles = (PolicyMapDTO) obj;                   
              processor.process(null, applicationRoles);               
            }            
    } 
    catch (JMSException |
              ClassCastException e) 
    {               
              logger.error("Exception encountered while invoking the service {} 
    in onMessage",                       
              THIS_COMPONENT_NAME, e);            
    } 
    catch(java.lang.Exception e) 
    {               
              logger.error("Exception encountered while invoking the service {} 
    in onMessage",                       
              THIS_COMPONENT_NAME, e);            
    }       
     }    
    }     
    private String getJNDIName(String name)
              {        
    return ServerPlatformUtils.detectServerPlatform().platformJNDIName(name);    
    }
    }