I have WildFly 10.1.0.Final, this have Artemis 1.1.0 Whats the correct way of configure jndi.properties?:
java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory
java.naming.provider.url=http-remoting://127.0.0.1:8080
jboss.naming.client.ejb.context=false
This worket with WildFly 9.0.0.Final that have HornetQ:
java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory
java.naming.provider.url=http-remoting://127.0.0.1:8080
jboss.naming.client.ejb.context=false
I'm using Spring 4.3.2, Spring-jms and included the wildfly-jms-client-bom in may Maven POM.xml. The Next is my connection Factory. Whith Wildfly 9 I try InitialContext.doLookup(..) and this work. But with WildFly 10 this don't work in same way.
My principal configuration files is:
@Configuration
@ComponentScan(basePackages = "org")
@Import({
MessagingConfiguration.class,
MessagingListenerConfiguration.class
})
public class AppConfig {
//Put Other Application configuration here.
}
.
package org.jms.configuration;
@Configuration
public class MessagingConfiguration {
@Bean
public ConnectionFactory connectionFactory() throws NamingException{
ConnectionFactory connectionFactory = InitialContext.doLookup("java:/ConnectionFactory");
return connectionFactory;
}
/*
@Bean
public JmsTemplate jmsTemplate() throws NamingException {
JmsTemplate template = new JmsTemplate();
template.setConnectionFactory(connectionFactory());
//template.setDefaultDestinationName(ORDER_RESPONSE_QUEUE);
return template;
}
*/
}
And I have the next:
package org.jms.configuration;
@Configuration
@EnableJms
public class MessagingListenerConfiguration {
@Autowired
ConnectionFactory connectionFactory;
public MessagingListenerConfiguration() {
System.out.println("MessagingListenerConfiguration::Constructor!!");
}
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setConcurrency("1-1");
return factory;
}
}
Finally I have this listener.
package org.jms.messaging;
import javax.jms.JMSException;
import org.gasmart.jms.model.Product;
import org.gasmart.jms.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.stereotype.Component;
@Component
public class MessageReceiver {
//private static final String ORDER_QUEUE = "order-queue";
/*
* <jms-queue name="shatTopic" entries="java:/jms/queue/shat java:/jboss/exported/jms/queue/shat"/>
*/
private static final String ORDER_QUEUE = "shat";
public MessageReceiver() {
System.out.println(">>>>>>>>>>>>>>>>>>> OK");
}
@Autowired
OrderService orderService;
@JmsListener(destination = ORDER_QUEUE)
public void receiveMessage(final Message<String> message) {
MessageHeaders headers = message.getHeaders();
System.out.println("MessageReceiver::receiveMessage(product) Application : headers received : "+headers);
//orderService.processOrder(product);
}
}
I get this error:
20:04:42,971 WARN [org.springframework.jms.listener.DefaultMessageListenerContainer] (DefaultMessageListenerContainer-124) Setup of JMS message listener invoker failed for destination 'shat' - trying to recover. Cause: There is no queue with name shat
20:04:42,971 INFO [org.springframework.jms.listener.DefaultMessageListenerContainer] (DefaultMessageListenerContainer-124) Successfully refreshed JMS Connection
The shat queue es declared in MessageReceiver class. My standalone-full.xml is the next:
<subsystem xmlns="urn:jboss:domain:messaging-activemq:1.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>
<security-setting name="jms.topic.chat">
<role name="guest2" send="true" consume="true" create-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>
<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>
<remote-acceptor name="websocket-stomp" socket-binding="netty-ws"/>
<in-vm-acceptor name="in-vm" server-id="0"/>
<jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>
<jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>
<jms-queue name="shatTopic" entries="java:/jms/queue/shat java:/jboss/exported/jms/queue/shat"/>
<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"/>
</server>
</subsystem>
I have defined the queue, that is correctly defined:
References about how declare a queue can consult here: http://www.mastertheboss.com/jboss-server/jboss-jms/jboss-jms-configuration
Why I cant connect?? I don't understand. I actually tryied many many ways, don't work.
UPDATE: 2016-August-29 - 10:00 A.M
I found that if I restart all the wildfly with the application actually deployed, after load the application, If I connect a client (I have a Web client that produce messages directly to the "jms.queue.shat" queue using Websocket over STOMP with stomp.js) and send messages, the application (java) consume correctly the messages. But if I redeploy the application after it was correctly working, this beging to produce ERROR. The errors is next:
10:43:51,607 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool - 113) WFLYUT0021: Registered web context: /ServerApp
10:43:51,632 INFO [org.jboss.as.server] (DeploymentScanner-threads - 2) WFLYSRV0010: Deployed "ServApp.war" (runtime-name : "ServApp.war")
10:43:56,588 INFO [org.springframework.jms.listener.DefaultMessageListenerContainer] (DefaultMessageListenerContainer-2) JMS message listener invoker needs to establish shared Connection
10:43:56,592 ERROR [org.springframework.jms.listener.DefaultMessageListenerContainer] (DefaultMessageListenerContainer-2) Could not refresh JMS Connection for destination 'shat' - retrying using FixedBackOff{interval=5000, currentAttempts=0, maxAttempts=unlimited}. Cause: Failed to create session factory; nested exception is java.lang.IllegalStateException: Server locator is closed (maybe it was garbage collected)
10:44:01,592 ERROR [org.springframework.jms.listener.DefaultMessageListenerContainer] (DefaultMessageListenerContainer-2) Could not refresh JMS Connection for destination 'shat' - retrying using FixedBackOff{interval=5000, currentAttempts=1, maxAttempts=unlimited}. Cause: Failed to create session factory; nested exception is java.lang.IllegalStateException: Server locator is closed (maybe it was garbage collected)
10:44:06,593 ERROR [org.springframework.jms.listener.DefaultMessageListenerContainer] (DefaultMessageListenerContainer-2) Could not refresh JMS Connection for destination 'shat' - retrying using FixedBackOff{interval=5000, currentAttempts=2, maxAttempts=unlimited}. Cause: Failed to create session factory; nested exception is java.lang.IllegalStateException: Server locator is closed (maybe it was garbage collected)
.....
The error say: JMS message listener invoker needs to establish shared Connection Could not refresh JMS Connection for destination 'shat'... Server locator is closed (maybe it was garbage collected)
Could be a Bug of ActiveMQ Artemis artemis 1.1.0.wildfly-017 ?
Some has resolved some similar?
UPDATE: 2016-August-29 - 14:00 P.M.
If someone is interested... I found that if you use JndiObjectFactoryBean to looks up a JNDI object, in this case the JMS connection factory, the before problem goes away. Normally I found some examples using JndiObjectFactoryBean but for get Database data sources, almost no example to obtain a JMS connection factory.
Changing MessagingConfiguration class:
@Bean
public ConnectionFactory connectionFactory() throws NamingException{
ConnectionFactory connectionFactory = InitialContext.doLookup("java:/ConnectionFactory");
return connectionFactory;
}
@Bean
public ConnectionFactory connectionFactory() throws NamingException{
return ConnectionFactory connectionFactory = InitialContext.doLookup("java:/ConnectionFactory");
}
with:
@Bean
public JndiObjectFactoryBean solicitudesConnectionFactory() {
JndiObjectFactoryBean jndi = new JndiObjectFactoryBean();
jndi.setJndiName("java:/ConnectionFactory");
jndi.setLookupOnStartup(true);
jndi.setProxyInterface(ConnectionFactory.class);
return jndi;
}
public ConnectionFactory notificacionesConnectionFactory() {
return new SingleConnectionFactory((ConnectionFactory)solicitudesConnectionFactory().getObject());
}
the connection to Artemis work correctly too, incluse if I do redeploy of the aplication. But the jndi.properties file is not used more, and the "Server locator is closed" problem disappears.
I don't know if the JndiObjectFactoryBean if correct, but I will want continue using the jndi.properties file. How do it??