Skip to main content

Using JMSConfiguration from Java

To do this from Java, you need to initialize a JMSConfiguration object, then store a reference to it in a JMSConfigFeature, and then add that to the features in the server factory. The code that follows is fragmentary. Note that you can't use query parameters in the endpoint URI that you set in the server factory, all the configuration has to be in the JMSConfiguration object.

public static JMSConfiguration newJMSConfiguration(String taskId, String jmsBrokerUrl) {
        String destinationUri = "jms:queue:" + taskId;
        JMSConfiguration conf = new JMSConfiguration();
        conf.setRequestURI(destinationUri);
        JNDIConfiguration jndiConfig = new JNDIConfiguration();
        JndiTemplate jt = new JndiTemplate();
        Properties env = new Properties();
        env.put(Context.PROVIDER_URL, jmsBrokerUrl); 
        env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
        jt.setEnvironment(env);
        jndiConfig.setJndiConnectionFactoryName("ConnectionFactory");
        jndiConfig.setEnvironment(env);
        conf.setJndiTemplate(jt);
        conf.setTargetDestination("com.basistech.jug." + taskId);
        conf.setJndiConfig(jndiConfig);
        conf.setTimeToLive(0);
        return conf;
}
{
        JMSConfigFeature jmsConfigFeature = new JMSConfigFeature();
        JMSConfiguration jmsConfig = JmsUtils.newJMSConfiguration(taskId, jmsBrokerUrl);
        jmsConfig.setConcurrentConsumers(maxServiceThreads);
        jmsConfig.setMaxConcurrentConsumers(maxServiceThreads);
        jmsConfigFeature.setJmsConfig(jmsConfig);
        svrFactory.getFeatures().add(jmsConfigFeature);
        svrFactory.getFeatures().add(jmsConfigFeature);
 
        server = svrFactory.create();
}

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – let us know how we can improve!