2

I am new to ActiveMQ Artemis 2.8.0 trying to set up a cluster. Currently, I have added only one server and trying to connect it with UDP protocol from a standalone java class.

While executing Am getting below error.

javax.jms.JMSException: Failed to create session factory
    at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:846)
    at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:282)
    at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:277)
    at jmsdemo.UDPSender.sendMessageWithBroadCasting(UDPSender.java:47)
    at jmsdemo.UDPSender.main(UDPSender.java:24)
Caused by: ActiveMQConnectionTimedOutException[errorType=CONNECTION_TIMEDOUT message=AMQ219012: Timed out waiting to receive initial broadcast from cluster]
    at org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:757)
    at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:844) 

Here is my java client code:

    public class UDPSender {
        public static void main(final String[] args) throws Exception {
            sendMessageWithBroadCasting();

        }

        private static void sendMessageWithBroadCasting() {
            try {
                Hashtable<String, String> props = new Hashtable();
                props.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");
                String providerUrl = "udp://231.7.7.9:9876";
                props.put(Context.PROVIDER_URL, providerUrl);

                props.put(Context.SECURITY_PRINCIPAL, "admin");
                props.put(Context.SECURITY_CREDENTIALS, "admin");
                // props.put("queue.email", "myQueue");
                props.put("queue.email", "email");
                props.put("queue.customerQueue", "customerQueue");
                Context ctx = new InitialContext(props);

                System.out.println(ctx);

                ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup("ConnectionFactory");
                Connection connection = connectionFactory.createConnection("admin", "admin");
                Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                System.out.println(session);

                // Queue queue = session.createQueue("customerQueue");

                Destination destination = (Destination) ctx.lookup("email");


                //Sender
                String payload = "Important Task";
                Message msg = session.createTextMessage(payload);
                System.out.println("Destination: " + destination);
                MessageProducer producer = session.createProducer(destination);
                System.out.println("Sending text '" + payload + "'");
                producer.send(msg);
                System.out.println("Message Sent Successfully");

                // Receiver
                 MessageConsumer consumer = session.createConsumer(destination);
                 connection.start(); ActiveMQTextMessage textMsg = (ActiveMQTextMessage)
                 consumer.receive(); System.out.println(textMsg);
                 System.out.println("Received: " + textMsg.getText()); session.close();

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    }

broker.xml file:

`<acceptors>
  <acceptor name="artemis">tcp://0.0.0.0:61616?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT,OPENWIRE;useEpoll=true;amqpCredits=1000;amqpLowCredits=300</acceptor>
  <acceptor name="amqp">tcp://0.0.0.0:5672?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=AMQP;useEpoll=true;amqpCredits=1000;amqpLowCredits=300</acceptor>
      <acceptor name="stomp">tcp://0.0.0.0:61613?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=STOMP;useEpoll=true</acceptor>
      <acceptor name="hornetq">tcp://0.0.0.0:5445?anycastPrefix=jms.queue.;multicastPrefix=jms.topic.;protocols=HORNETQ,STOMP;useEpoll=true</acceptor>
      <acceptor name="mqtt">tcp://0.0.0.0:1883?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=MQTT;useEpoll=true</acceptor>
    </acceptors>



<connectors>
  <connector name="netty-connector">tcp://0.0.0.0:61616</connector>
</connectors>
<broadcast-groups>
  <broadcast-group name="my-broadcast-group">
    <local-bind-address>localhost</local-bind-address>
    <local-bind-port>-1</local-bind-port>
    <group-address>231.7.7.9</group-address>
    <group-port>9876</group-port>
    <broadcast-period>100</broadcast-period>
    <connector-ref>netty-connector</connector-ref>
  </broadcast-group>
</broadcast-groups>
<discovery-groups>
  <discovery-group name="my-discovery-group">
    <local-bind-address>localhost</local-bind-address>
    <local-bind-port>-1</local-bind-port>
    <group-address>231.7.7.9</group-address>
    <group-port>9876</group-port>
    <refresh-timeout>10000</refresh-timeout>
  </discovery-group>
</discovery-groups>
<cluster-connections>
  <cluster-connection name="my-cluster">
    <connector-ref>netty-connector</connector-ref>
    <retry-interval>500</retry-interval>
    <reconnect-attempts>5</reconnect-attempts>
    <use-duplicate-detection>true</use-duplicate-detection>
    <message-load-balancing>OFF</message-load-balancing>
    <max-hops>1</max-hops>
    <discovery-group-ref discovery-group-name="my-discovery-group"/>
  </cluster-connection>
</cluster-connections>
<ha-policy>
  <shared-store>
    <colocated>
      <backup-port-offset>100</backup-port-offset>
      <backup-request-retries>-1</backup-request-retries>
      <backup-request-retry-interval>2000</backup-request-retry-interval>
      <max-backups>1</max-backups>
      <request-backup>true</request-backup>
      <master>
        <failover-on-shutdown>true</failover-on-shutdown>
      </master>
      <slave>
        <scale-down/>
      </slave>
    </colocated>
  </shared-store>
</ha-policy>`

My objective is to lookup JMSQueue (with UDP protocol) and post a message it. Please help me.

Kapil
  • 817
  • 2
  • 13
  • 25
  • Can you confirm that UDP packets actually transmit between the client and the server? A lot of networks limit the use of UDP. – Justin Bertram Aug 08 '19 at 14:07
  • Yes, we required UDP only. – user1386039 Aug 08 '19 at 17:33
  • 1
    I'm not really sure what you mean by "we required UDP only." Does that mean that you've confirmed that your network supports UDP packet transmission between the broker and the client? – Justin Bertram Aug 09 '19 at 12:19
  • Thank you for spending time on my post. The issue resolved. The problem is I am trying to lookup the JMS queue ( with group-address and port) from standalone java application. I have moved the same piece of code to JBoss container then worked. – user1386039 Aug 13 '19 at 11:04
  • 1
    The `org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory` you're using to perform the queue lookup doesn't actually do remote lookups; it is a client-side only implementation (which is why you configure the queue name in the environment properties). Therefore, the problem couldn't be that you were "trying to lookup the JMS queue (with group-address and port) from standalone java application." Furthermore, the exception indicates that the failure occurred when trying to create the JMS connection, not when looking up the queue. – Justin Bertram Aug 13 '19 at 13:00

0 Answers0