You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by "aries.aries" <ar...@gmail.com> on 2016/08/21 12:55:55 UTC

Using JMS in ActiveMQ Artemis

I am trying to use JMS to send message to a durable queue by referring the
"SimpleQueueSender" example. Below is my code that I am using inside my
interceptor module. 
I have defined the queue in broker.xml. However, when I run the broker
instance I get the below error

ERROR [org.apache.activemq.artemis.core.server] AMQ224000: Failure in
initialisation: java.security.PrivilegedActionException:
javax.naming.NameNotFoundException; remaining name 'QueueConnectionFactory'
..
..
Caused by: javax.naming.NameNotFoundException; remaining name
'QueueConnectionFactory'

Could someone please guide me what I might be missing? Does it needs any
more configuration or something? Much Appreciated.

My code:

	Context jndiContext = new InitialContext();
	QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory)
jndiContext.lookup("QueueConnectionFactory");
	Queue queue = (Queue) jndiContext.lookup("exampleQueue");
	QueueConnection queueConnection  =
queueConnectionFactory.createQueueConnection();
	QueueSession queueSession = queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
	MessageConsumer consumer = queueSession.createConsumer(queue);
	QueueSender queueSender = queueSession.createSender(queue);
	ObjectMessage message = queueSession.createObjectMessage();
	message.setObject(results);
	queueSender.send(message);
	queueSender.send(queueSession.createMessage());
	queueConnection.close();

broker.xml

   <jms xmlns="urn:activemq:jms">
      <queue name="exampleQueue">
         <durable>true</durable>
      </queue>
   </jms>



--
View this message in context: http://activemq.2283324.n4.nabble.com/Using-JMS-in-ActiveMQ-Artemis-tp4715693.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.

Re: Using JMS in ActiveMQ Artemis

Posted by Justin Bertram <jb...@apache.com>.
Just use the core API.  It will be much simpler that way.  Here's a very basic example:

      ServerLocator locator = ActiveMQClient.createServerLocator("vm://0");
      ClientSessionFactory sf = locator.createSessionFactory();
      ClientSession session = sf.createSession(false, true, true);
      ClientProducer producer = session.createProducer("myQueue");
      ClientMessage message = session.createMessage(true);
      message.getBodyBuffer().writeString("myData");
      producer.send(message);
      locator.close();

Of course you won't want to create a ServerLocator, ClientSessionFactory, ClientSession, and ClientProducer *every* time you want to send a message, but you get the idea.


Justin

----- Original Message -----
From: "aries.aries" <ar...@gmail.com>
To: dev@activemq.apache.org
Sent: Monday, August 22, 2016 1:45:24 PM
Subject: Re: Using JMS in ActiveMQ Artemis

Sorry may be the "interceptor module" is bit confusing. Basically I am
intercepting mqtt messages and doing some computations. I want these values
to be available on the slave as well when it takes over the master. I need
to use the values to resume the computation. So I send the values to a
durable queue so that I get the values from the queue when the slave takes
over the master.

Can you please tell me how can I get this to work? Do I need to create a
jndi.properties file to define the configuration?



--
View this message in context: http://activemq.2283324.n4.nabble.com/Using-JMS-in-ActiveMQ-Artemis-tp4715693p4715713.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.

Re: Using JMS in ActiveMQ Artemis

Posted by "aries.aries" <ar...@gmail.com>.
Sorry may be the "interceptor module" is bit confusing. Basically I am
intercepting mqtt messages and doing some computations. I want these values
to be available on the slave as well when it takes over the master. I need
to use the values to resume the computation. So I send the values to a
durable queue so that I get the values from the queue when the slave takes
over the master.

Can you please tell me how can I get this to work? Do I need to create a
jndi.properties file to define the configuration?



--
View this message in context: http://activemq.2283324.n4.nabble.com/Using-JMS-in-ActiveMQ-Artemis-tp4715693p4715713.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.

Re: Using JMS in ActiveMQ Artemis

Posted by Justin Bertram <jb...@apache.com>.
Artemis' JNDI implementation is client-side only which means that JMS connection factories are configured in jndi.properties or programmatically in the environment of the appropriate initial context.  Therefore you won't find connection factory configuration details in broker.xml.

I'm a bit confused by the use-case here.  You mentioned that you're sending a message from your "interceptor module".  Can you clarify what exactly this is?  Is it an Artemis remoting interceptor?  If so, you should use the core API here rather than JMS as it would be much simpler.


Justin

----- Original Message -----
From: "aries.aries" <ar...@gmail.com>
To: dev@activemq.apache.org
Sent: Monday, August 22, 2016 11:09:25 AM
Subject: Re: Using JMS in ActiveMQ Artemis

Below is the entire content of Broker.xml

<?xml version='1.0'?>
<configuration xmlns="urn:activemq"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="urn:activemq
/schema/artemis-configuration.xsd">

   <jms xmlns="urn:activemq:jms">
      <queue name="exampleQueue">
         <durable>true</durable>
      </queue>
   </jms>

   <core xmlns="urn:activemq:core">
      <name>master</name>
      <persistence-enabled>true</persistence-enabled>
      <journal-type>NIO</journal-type>
      <paging-directory>./data/paging</paging-directory>
      <bindings-directory>./data/bindings</bindings-directory>
      <journal-directory>./data/journal</journal-directory>
     
<large-messages-directory>./data/large-messages</large-messages-directory>
      <journal-min-files>2</journal-min-files>
      <journal-pool-files>-1</journal-pool-files>
      <journal-buffer-timeout>68000</journal-buffer-timeout>

      <remoting-incoming-interceptors>
        
<class-name>org.apache.activemq.artemis.core.protocol.mqtt.SamplingBrokerInterceptor</class-name>
      </remoting-incoming-interceptors>
      
      <ha-policy>
         <replication>
            <master>
               <check-for-live-server>true</check-for-live-server>
            </master>
         </replication>
      </ha-policy>      

      <connectors>
         <connector
name="netty-connector">tcp://172.24.25.123:61616</connector>
      </connectors>
      
      <acceptors>
         <acceptor
name="netty-acceptor">tcp://172.24.25.123:61616</acceptor>
      </acceptors>

      <broadcast-groups>
         <broadcast-group name="bg-group1">
            <group-address>${udp-address:231.7.7.7}</group-address>
            <group-port>9876</group-port>
            <broadcast-period>1000</broadcast-period>
            <connector-ref>netty-connector</connector-ref>
         </broadcast-group>
      </broadcast-groups>

      <discovery-groups>
         <discovery-group name="dg-group1">
            <group-address>${udp-address:231.7.7.7}</group-address>
            <group-port>9876</group-port>
            <refresh-timeout>5000</refresh-timeout>
         </discovery-group>
      </discovery-groups>

      <cluster-connections>
         <cluster-connection name="my-cluster">
            <address>jms</address>
            <connector-ref>netty-connector</connector-ref>
            <discovery-group-ref discovery-group-name="dg-group1"/>
         </cluster-connection>
      </cluster-connections>

      <security-settings>
         <security-setting match="#">
            <permission type="createNonDurableQueue" roles="a"/>
            <permission type="deleteNonDurableQueue" roles="a"/>
            <permission type="createDurableQueue" roles="a"/>
            <permission type="deleteDurableQueue" roles="a"/>
            <permission type="consume" roles="a"/>
            <permission type="browse" roles="a"/>
            <permission type="send" roles="a"/>
            <permission type="manage" roles="a"/>
         </security-setting>
      </security-settings>

   </core>
</configuration>




--
View this message in context: http://activemq.2283324.n4.nabble.com/Using-JMS-in-ActiveMQ-Artemis-tp4715693p4715709.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.

Re: Using JMS in ActiveMQ Artemis

Posted by "aries.aries" <ar...@gmail.com>.
Below is the entire content of Broker.xml

<?xml version='1.0'?>
<configuration xmlns="urn:activemq"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="urn:activemq
/schema/artemis-configuration.xsd">

   <jms xmlns="urn:activemq:jms">
      <queue name="exampleQueue">
         <durable>true</durable>
      </queue>
   </jms>

   <core xmlns="urn:activemq:core">
      <name>master</name>
      <persistence-enabled>true</persistence-enabled>
      <journal-type>NIO</journal-type>
      <paging-directory>./data/paging</paging-directory>
      <bindings-directory>./data/bindings</bindings-directory>
      <journal-directory>./data/journal</journal-directory>
     
<large-messages-directory>./data/large-messages</large-messages-directory>
      <journal-min-files>2</journal-min-files>
      <journal-pool-files>-1</journal-pool-files>
      <journal-buffer-timeout>68000</journal-buffer-timeout>

      <remoting-incoming-interceptors>
        
<class-name>org.apache.activemq.artemis.core.protocol.mqtt.SamplingBrokerInterceptor</class-name>
      </remoting-incoming-interceptors>
      
      <ha-policy>
         <replication>
            <master>
               <check-for-live-server>true</check-for-live-server>
            </master>
         </replication>
      </ha-policy>      

      <connectors>
         <connector
name="netty-connector">tcp://172.24.25.123:61616</connector>
      </connectors>
      
      <acceptors>
         <acceptor
name="netty-acceptor">tcp://172.24.25.123:61616</acceptor>
      </acceptors>

      <broadcast-groups>
         <broadcast-group name="bg-group1">
            <group-address>${udp-address:231.7.7.7}</group-address>
            <group-port>9876</group-port>
            <broadcast-period>1000</broadcast-period>
            <connector-ref>netty-connector</connector-ref>
         </broadcast-group>
      </broadcast-groups>

      <discovery-groups>
         <discovery-group name="dg-group1">
            <group-address>${udp-address:231.7.7.7}</group-address>
            <group-port>9876</group-port>
            <refresh-timeout>5000</refresh-timeout>
         </discovery-group>
      </discovery-groups>

      <cluster-connections>
         <cluster-connection name="my-cluster">
            <address>jms</address>
            <connector-ref>netty-connector</connector-ref>
            <discovery-group-ref discovery-group-name="dg-group1"/>
         </cluster-connection>
      </cluster-connections>

      <security-settings>
         <security-setting match="#">
            <permission type="createNonDurableQueue" roles="a"/>
            <permission type="deleteNonDurableQueue" roles="a"/>
            <permission type="createDurableQueue" roles="a"/>
            <permission type="deleteDurableQueue" roles="a"/>
            <permission type="consume" roles="a"/>
            <permission type="browse" roles="a"/>
            <permission type="send" roles="a"/>
            <permission type="manage" roles="a"/>
         </security-setting>
      </security-settings>

   </core>
</configuration>




--
View this message in context: http://activemq.2283324.n4.nabble.com/Using-JMS-in-ActiveMQ-Artemis-tp4715693p4715709.html
Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.

Re: Using JMS in ActiveMQ Artemis

Posted by "John D. Ament" <jo...@apache.org>.
The error is referring to your connection factory.  Could you please post
your entire broker.xml?

On Sun, Aug 21, 2016 at 11:54 AM aries.aries <ar...@gmail.com>
wrote:

> I am trying to use JMS to send message to a durable queue by referring the
> "SimpleQueueSender" example. Below is my code that I am using inside my
> interceptor module.
> I have defined the queue in broker.xml. However, when I run the broker
> instance I get the below error
>
> ERROR [org.apache.activemq.artemis.core.server] AMQ224000: Failure in
> initialisation: java.security.PrivilegedActionException:
> javax.naming.NameNotFoundException; remaining name 'QueueConnectionFactory'
> ..
> ..
> Caused by: javax.naming.NameNotFoundException; remaining name
> 'QueueConnectionFactory'
>
> Could someone please guide me what I might be missing? Does it needs any
> more configuration or something? Much Appreciated.
>
> My code:
>
>         Context jndiContext = new InitialContext();
>         QueueConnectionFactory queueConnectionFactory =
> (QueueConnectionFactory)
> jndiContext.lookup("QueueConnectionFactory");
>         Queue queue = (Queue) jndiContext.lookup("exampleQueue");
>         QueueConnection queueConnection  =
> queueConnectionFactory.createQueueConnection();
>         QueueSession queueSession =
> queueConnection.createQueueSession(false,
> Session.AUTO_ACKNOWLEDGE);
>         MessageConsumer consumer = queueSession.createConsumer(queue);
>         QueueSender queueSender = queueSession.createSender(queue);
>         ObjectMessage message = queueSession.createObjectMessage();
>         message.setObject(results);
>         queueSender.send(message);
>         queueSender.send(queueSession.createMessage());
>         queueConnection.close();
>
> broker.xml
>
>    <jms xmlns="urn:activemq:jms">
>       <queue name="exampleQueue">
>          <durable>true</durable>
>       </queue>
>    </jms>
>
>
>
> --
> View this message in context:
> http://activemq.2283324.n4.nabble.com/Using-JMS-in-ActiveMQ-Artemis-tp4715693.html
> Sent from the ActiveMQ - Dev mailing list archive at Nabble.com.
>