I am trying to connect to a SoftwareAg's Universal Messaging queue in a Spring application. This is my Config
class.
@Configuration
@EnableJms
public class Config {
@Bean
public ActiveMQConnectionFactory receiverActiveMQConnectionFactory() {
ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
var properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.pcbsys.nirvana.nSpace.NirvanaContextFactory");
properties.setProperty(Context.PROVIDER_URL, "nsp://localhost:9200");
activeMQConnectionFactory.buildFromProperties(properties);
return activeMQConnectionFactory;
}
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
var factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(receiverActiveMQConnectionFactory());
factory.setConcurrency("3-10");
return factory;
}
}
This is the part of my pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
</dependency>
<dependency>
<groupId>com.pcbsys.nirvana</groupId>
<artifactId>nClient</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.pcbsys.nirvana</groupId>
<artifactId>nJMS</artifactId>
<version>1.0</version>
</dependency>
However, I get the following exception when I try to connect to the queue:
Caused by: org.springframework.jms.UncategorizedJmsException: Uncategorized exception occurred during JMS processing; nested exception is javax.jms.JMSException: Could not create Transport. Reason: java.io.IOException: Transport scheme NOT recognized: [nsp]
at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:311) ~[spring-jms-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:185) ~[spring-jms-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:507) ~[spring-jms-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:584) ~[spring-jms-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.jms.core.JmsTemplate.convertAndSend(JmsTemplate.java:661) ~[spring-jms-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at id.mandiri.co.id.um.Main.lambda$runner$0(Main.java:21) ~[classes/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:784) ~[spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
... 5 common frames omitted
Caused by: javax.jms.JMSException: Could not create Transport. Reason: java.io.IOException: Transport scheme NOT recognized: [nsp]
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36) ~[activemq-client-5.15.10.jar:5.15.10]
at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:333) ~[activemq-client-5.15.10.jar:5.15.10]
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:346) ~[activemq-client-5.15.10.jar:5.15.10]
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:304) ~[activemq-client-5.15.10.jar:5.15.10]
at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:244) ~[activemq-client-5.15.10.jar:5.15.10]
at org.springframework.jms.support.JmsAccessor.createConnection(JmsAccessor.java:196) ~[spring-jms-5.2.1.RELEASE.jar:5.2.1.RELEASE]
at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:494) ~[spring-jms-5.2.1.RELEASE.jar:5.2.1.RELEASE]
... 9 common frames omitted
Caused by: java.io.IOException: Transport scheme NOT recognized: [nsp]
at org.apache.activemq.util.IOExceptionSupport.create(IOExceptionSupport.java:28) ~[activemq-client-5.15.10.jar:5.15.10]
at org.apache.activemq.transport.TransportFactory.findTransportFactory(TransportFactory.java:185) ~[activemq-client-5.15.10.jar:5.15.10]
at org.apache.activemq.transport.TransportFactory.connect(TransportFactory.java:64) ~[activemq-client-5.15.10.jar:5.15.10]
at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:331) ~[activemq-client-5.15.10.jar:5.15.10]
... 14 common frames omitted
Caused by: java.io.IOException: Could not find factory class for resource: META-INF/services/org/apache/activemq/transport/nsp
at org.apache.activemq.util.FactoryFinder$StandaloneObjectFactory.loadProperties(FactoryFinder.java:98) ~[activemq-client-5.15.10.jar:5.15.10]
at org.apache.activemq.util.FactoryFinder$StandaloneObjectFactory.create(FactoryFinder.java:60) ~[activemq-client-5.15.10.jar:5.15.10]
at org.apache.activemq.util.FactoryFinder.newInstance(FactoryFinder.java:148) ~[activemq-client-5.15.10.jar:5.15.10]
at org.apache.activemq.transport.TransportFactory.findTransportFactory(TransportFactory.java:182) ~[activemq-client-5.15.10.jar:5.15.10]
... 16 common frames omitted
It says here:
UM can be used with Spring. In general, the Spring XML that works for ActiveMQ should work for UM with only the connection factory class and URL changed accordingly.
What am I missing?
Edit:
var properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.pcbsys.nirvana.nSpace.NirvanaContextFactory");
properties.setProperty(Context.PROVIDER_URL, "nsp://localhost:9200");
Context ctx = new InitialContext(properties);
return (ConnectionFactory) ctx.lookup("local_um"); // THIS?
I finally managed to solve it. This is what worked for me:
@Configuration
@EnableJms
public class Config {
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
var factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(cachingConnectionFactory());
factory.setConcurrency("3-10");
return factory;
}
@Bean
@Primary
public CachingConnectionFactory cachingConnectionFactory() {
final CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
cachingConnectionFactory.setSessionCacheSize(200);
cachingConnectionFactory.setTargetConnectionFactory((ConnectionFactory) jndiObjectFactoryBean().getObject());
return cachingConnectionFactory;
}
@Bean
public JndiTemplate jndiTemplate() {
final Properties properties = new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.pcbsys.nirvana.nSpace.NirvanaContextFactory");
properties.setProperty(Context.PROVIDER_URL, "nsp://local-dev:9200");
final JndiTemplate jndiTemplate = new JndiTemplate();
jndiTemplate.setEnvironment(properties);
return jndiTemplate;
}
@Bean
public JndiObjectFactoryBean jndiObjectFactoryBean() {
final JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
jndiObjectFactoryBean.setJndiTemplate(jndiTemplate());
jndiObjectFactoryBean.setJndiName("jndi_key");
return jndiObjectFactoryBean;
}
}
I hope it helps someone. Don't forget to add nClient.jar
and nJMS.jar
to your classpath. You can find them in the UM install lib
directory.