How to use dynamic topics with ActiveMQ-Artemis and Wildfly ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to use dynamic topics with ActiveMQ-Artemis and Wildfly ?

StevenACS
My goal is to subscribe to dynamic topics (= topics created dynamically in runtime) close to a remote message broker provided by ActiveMq-Artemis.

As mentioned in https://developer.jboss.org/wiki/HowToUseOutOfProcessActiveMQWithWildFly,
I tried to use ActiveMQ Resource Adaptater either by including activemq-rar.rar in WildFly deployments directory
or by creating a JBoss module containing the RA code
but neither solution works.
If someone has an idea I will be very grateful :-)

Let us take the first solution activemq-rar.rar in WildFly deployments directory (in fact the RA is inserted in my ear called cse.ear)
ISSUE : when Wildfly starts, I do not see the log "Registered connection factory java:/ConnectionFactory".
And in runtime I have an exception :

Unable to instantiate endpoint: java.lang.IllegalArgumentException: WFLYWELD0049: Error injecting resource into CDI managed bean. Can't find a resource named java:/ConnectionFactory defined on javax.jms.ConnectionFactory


You can see below the complete exception, my Wildfly configuration and the code for the topic subscrition:
15:43:29,735 ERROR [io.undertow.websockets.jsr.request] (default task-5) UT026001: Unable to instantiate endpoint: java.lang.IllegalArgumentException: WFLYWELD0049: Error injecting resource into CDI managed bean. Can't find a resource named java:/ConnectionFactory defined on javax.jms.ConnectionFactory 
	at org.jboss.as.weld.services.bootstrap.WeldResourceInjectionServices.resolveResource(WeldResourceInjectionServices.java:216)
	at org.jboss.as.weld.services.bootstrap.WeldResourceInjectionServices$1.createResource(WeldResourceInjectionServices.java:162)
	at org.jboss.weld.injection.AbstractResourceInjection.getResourceReference(AbstractResourceInjection.java:49)
	at org.jboss.weld.injection.AbstractResourceInjection.injectResourceReference(AbstractResourceInjection.java:63)
	at org.jboss.weld.util.Beans.injectEEFields(Beans.java:351)
	at org.jboss.weld.injection.producer.ResourceInjector$1.proceed(ResourceInjector.java:69)
	at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)
	at org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:72)
	at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:121)
	at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:159)
	at org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:70)
	at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:101)
	at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
	at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:742)
	at org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:842)
	at org.jboss.weld.injection.ParameterInjectionPointImpl.getValueToInject(ParameterInjectionPointImpl.java:76)
	at org.jboss.weld.injection.StaticMethodInjectionPoint.getParameterValues(StaticMethodInjectionPoint.java:127)
	at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:78)
	at org.jboss.weld.util.Beans.callInitializers(Beans.java:402)
	at org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:390)
	at org.jboss.weld.injection.producer.DefaultInjector$1.proceed(DefaultInjector.java:71)
	at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)
	at org.jboss.weld.injection.producer.DefaultInjector.inject(DefaultInjector.java:73)
	at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:121)
	at org.jboss.as.weld.deployment.WeldClassIntrospector$1.getReference(WeldClassIntrospector.java:63)
	at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$ManagedReferenceInstanceFactory.createInstance(UndertowDeploymentInfoService.java:1445)
	at io.undertow.websockets.jsr.DefaultContainerConfigurator.getEndpointInstance(DefaultContainerConfigurator.java:87)
	at javax.websocket.server.ServerEndpointConfig$Configurator.getEndpointInstance(ServerEndpointConfig.java:239)
	at io.undertow.websockets.jsr.EndpointSessionHandler.onConnect(EndpointSessionHandler.java:73)
	at io.undertow.websockets.jsr.JsrWebSocketFilter$1.handleUpgrade(JsrWebSocketFilter.java:121)
	at io.undertow.server.protocol.http.HttpReadListener.exchangeComplete(HttpReadListener.java:361)
	at io.undertow.server.protocol.http.HttpServerConnection.exchangeComplete(HttpServerConnection.java:228)
	at io.undertow.server.HttpServerExchange$ExchangeCompleteNextListener.proceed(HttpServerExchange.java:1802)
	at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler$1.exchangeEvent(GlobalRequestControllerHandler.java:25)
	at io.undertow.server.HttpServerExchange.invokeExchangeCompleteListeners(HttpServerExchange.java:1223)
	at io.undertow.server.HttpServerExchange.terminateResponse(HttpServerExchange.java:1503)
	at io.undertow.server.Connectors.terminateResponse(Connectors.java:99)
	at io.undertow.server.protocol.http.HttpTransferEncoding$3.handleEvent(HttpTransferEncoding.java:197)
	at io.undertow.server.protocol.http.HttpTransferEncoding$3.handleEvent(HttpTransferEncoding.java:195)
	at io.undertow.conduits.HeadStreamSinkConduit.exitFlush(HeadStreamSinkConduit.java:178)
	at io.undertow.conduits.HeadStreamSinkConduit.flush(HeadStreamSinkConduit.java:122)
	at org.xnio.conduits.ConduitStreamSinkChannel.flush(ConduitStreamSinkChannel.java:162)
	at io.undertow.channels.DetachableStreamSinkChannel.flush(DetachableStreamSinkChannel.java:119)
	at org.xnio.channels.Channels.flushBlocking(Channels.java:63)
	at io.undertow.servlet.spec.ServletOutputStreamImpl.close(ServletOutputStreamImpl.java:609)
	at io.undertow.servlet.spec.HttpServletResponseImpl.closeStreamAndWriter(HttpServletResponseImpl.java:476)
	at io.undertow.servlet.spec.HttpServletResponseImpl.responseDone(HttpServletResponseImpl.java:560)
	at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:331)
	at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)
	at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
	at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)
	at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
	at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: javax.naming.NameNotFoundException: ConnectionFactory -- service jboss.naming.context.java.ConnectionFactory
	at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:106)
	at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:207)
	at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:235)
	at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:193)
	at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:189)
	at javax.naming.InitialContext.lookup(InitialContext.java:417)
	at javax.naming.InitialContext.lookup(InitialContext.java:417)
	at org.jboss.as.weld.services.bootstrap.WeldResourceInjectionServices.resolveResource(WeldResourceInjectionServices.java:214)
	... 55 more

      <subsystem xmlns="urn:jboss:domain:resource-adapters:4.0">
            <resource-adapters>
                <resource-adapter id="activemq-rar.rar">
                    <archive>
                        cse.ear#activemq-rar.rar
                    </archive>
                    <transaction-support>XATransaction</transaction-support>
                    <config-property name="ServerUrl">
                        tcp://localhost:61616?jms.rmIdFromConnectionId=true
                    </config-property>
                    <config-property name="UserName">
                        defaultUser
                    </config-property>
                    <config-property name="UseInboundSession">
                        false
                    </config-property>
                    <config-property name="Password">
                        defaultPassword
                    </config-property>
                    <connection-definitions>
                        <connection-definition class-name="org.apache.activemq.ra.ActiveMQManagedConnectionFactory" jndi-name="java:/ConnectionFactory" enabled="true" pool-name="ConnectionFactory">
                            <xa-pool>
                                <min-pool-size>1</min-pool-size>
                                <max-pool-size>20</max-pool-size>
                                <prefill>false</prefill>
                                <is-same-rm-override>false</is-same-rm-override>
                            </xa-pool>
                        </connection-definition>
                    </connection-definitions>
                </resource-adapter>
            </resource-adapters>
        </subsystem>
 
        <subsystem xmlns="urn:jboss:domain:ejb3:4.0">
            <session-bean>
                <stateful default-access-timeout="5000" cache-ref="simple" passivation-disabled-cache-ref="simple"/>
                <singleton default-access-timeout="5000"/>
            </session-bean>
            <mdb>
                <resource-adapter-ref resource-adapter-name="activemq-rar"/>
                <bean-instance-pool-ref pool-name="mdb-strict-max-pool"/>
            </mdb>
           ...


import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.annotation.Resource;
import javax.inject.Inject;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSConsumer;
import javax.jms.JMSContext;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.Topic;

import org.jboss.ejb3.annotation.ResourceAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@ResourceAdapter("activemq-rar")
public class DurableSubscribeToBroker {

    private ConsumerMessageListener consumerListener;
       
    public DurableSubscribeToBroker(){
    }
   
    @Resource(lookup = "java:/ConnectionFactory")
    ConnectionFactory cf;
       
    @Inject
    public void setConsumerMessageListener(ConsumerMessageListener consumerListener) {
                this.consumerListener = consumerListener;
    }

    public void subscribe(String durableSubscriptionName) throws JMSException {
    Connection connection = cf.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   
       Topic topic = session.createTopic("myDynamicTopic");
    session.createDurableSubscriber(topic, durableSubscriptionName);

        MessageConsumer consumer = session.createConsumer(topic);
        consumer.setMessageListener(consumerListener);
    }
Reply | Threaded
Open this post in threaded view
|

Re: How to use dynamic topics with ActiveMQ-Artemis and Wildfly ?

StevenACS
This post was updated on .
Issue solved.

I put the resource adapter directly in the Wildfly directory deploiement and I changed the standalone configuration file like that :
   
<archive>
      activemq-rar.rar
   </archive>