Hi there,

I have modified the "Hello.java" sample of qpid-client-0.30 JMS client to
connect to RabbitMQ v3.3.5, but this does not work.

My JNDI config (hello.properties) is:

-----------------------.-----------------------
java.naming.factory.initial =
org.apache.qpid.jndi.PropertiesFileInitialContextFactory
#### RabbitMQ v3.3.5
connectionfactory.myRabbitMQConnectionFactory1 = amqp://admin:xxx@clientid
/DES_DEV?brokerlist='tcp://10.105.135.53:5672'
connectionfactory.myRabbitMQConnectionFactory2 = amqp://admin:xxx@clientid
/?brokerlist='tcp://10.105.135.53:5672'
queue.myJNDIRabbitMQQueue1 = q.test1
queue.myJNDIRabbitMQQueue2 = q.test2
-----------------------.-----------------------

And my updated Hello.java is:

-----------------------.-----------------------
import java.io.InputStream;
import java.util.Properties;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;

public class Hello {

    public Hello() {
    }

    public static void main(String[] args) {
        Hello hello = new Hello();
        hello.runTest();
    }

    private void runTest()  {
        try (InputStream resourceAsStream =
this.getClass().getResourceAsStream("hello.properties")) {
            System.setProperty("qpid.amqp.version", "0-91");
            Properties properties = new Properties();
            properties.load(resourceAsStream);
            Context context = new InitialContext(properties);

            ConnectionFactory connectionFactory = (ConnectionFactory)
context.lookup("myRabbitMQConnectionFactory1");
            //ConnectionFactory connectionFactory = (ConnectionFactory)
context.lookup("myRabbitMQConnectionFactory2");
            Connection connection = connectionFactory.createConnection();
            connection.start();
            Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);

            Queue queue = (Queue) context.lookup("myJNDIRabbitMQQueue1");
            //Queue queue = (Queue) context.lookup("myJNDIRabbitMQQueue2");
            MessageProducer messageProducer = session.createProducer(queue);
            TextMessage message = session.createTextMessage("Hello world
!!");
            messageProducer.send(message);

            System.out.println(message.getText());
            connection.close();
            context.close();
        } catch (Exception exp) {
            exp.printStackTrace();
        }
    }
}
-----------------------.-----------------------


If I use (with VIRTUAL HOST):

connectionfactory.myRabbitMQConnectionFactory1 = amqp://admin:xxx@
*clientid/DES_DEV*?brokerlist='tcp://10.105.135.53:5672'

I have this error:

-----------------------.-----------------------
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further
details.
javax.jms.JMSException: Error creating connection: Exception thrown against
AMQConnection:
Host: 10.105.135.53
Port: 5672
Virtual Host: DES_DEV
Client ID: clientid
Active session count: 0: org.apache.qpid.AMQDisconnectedException:
Connection could not be established: Connection reset
    at
org.apache.qpid.client.AMQConnectionFactory.createConnection(AMQConnectionFactory.java:128)
    at info.intix.rabbitmq.samples.Hello.runTest(Hello.java:39)
    at info.intix.rabbitmq.samples.Hello.main(Hello.java:21)
Caused by: org.apache.qpid.AMQConnectionFailureException: Exception thrown
against AMQConnection:
Host: 10.105.135.53
Port: 5672
Virtual Host: DES_DEV
Client ID: clientid
Active session count: 0: org.apache.qpid.AMQDisconnectedException:
Connection could not be established: Connection reset
    at org.apache.qpid.client.AMQConnection.<init>(AMQConnection.java:503)
    at
org.apache.qpid.client.AMQConnectionFactory.createConnection(AMQConnectionFactory.java:124)
    ... 2 more
Caused by: org.apache.qpid.AMQException: Woken up due to class
javax.jms.JMSException
    at
org.apache.qpid.client.util.BlockingWaiter.block(BlockingWaiter.java:195)
    at org.apache.qpid.client.state.StateWaiter.await(StateWaiter.java:114)
    at org.apache.qpid.client.state.StateWaiter.await(StateWaiter.java:91)
    at org.apache.qpid.client.*AMQConnectionDelegate_8_0*
.makeBrokerConnection(AMQConnectionDelegate_8_0.java:142)
    at
org.apache.qpid.client.AMQConnection.makeBrokerConnection(AMQConnection.java:647)
    at org.apache.qpid.client.AMQConnection.<init>(AMQConnection.java:429)
    ... 3 more
Caused by: javax.jms.JMSException: Exception thrown against AMQConnection:
Host: 10.105.135.53
Port: 5672
Virtual Host: DES_DEV
Client ID: clientid
Active session count: 0: org.apache.qpid.AMQDisconnectedException:
Connection could not be established: Connection reset
    at
org.apache.qpid.client.AMQConnection.exceptionReceived(AMQConnection.java:1313)
    at
org.apache.qpid.client.protocol.AMQProtocolHandler.closed(AMQProtocolHandler.java:285)
    at
org.apache.qpid.transport.network.io.IoReceiver.run(IoReceiver.java:222)
    at java.lang.Thread.run(Thread.java:744)
Caused by: org.apache.qpid.AMQDisconnectedException: Connection could not
be established: Connection reset
    ... 3 more
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:196)
    at java.net.SocketInputStream.read(SocketInputStream.java:122)
    at
org.apache.qpid.transport.network.io.IoReceiver.run(IoReceiver.java:156)
-----------------------.-----------------------

In "Hello.java" i have defined the AMQP version to 0.91, but seems that is
not used. RabbitMQ v3.3.5 implements AMQP 0-9-1.

But, If I use (connectionfactory.myRabbitMQConnectionFactory2 =
amqp://admin:xxx@*clientid*/?brokerlist='tcp://10.105.135.53:5672'  -
without VIRTUAL HOST):

* There are not errors, seems the message was published... but there is not
messages in the queue.
* In the RabbitMQ web admin console I can see a new connection created.
This new connection has "Protocol = AMQP 0-9-1" and "Client = qpid 0.30 /
Java ...".
You can check it here:
https://www.dropbox.com/s/ek5r5qgvripewdz/rabbitmq-qpid-jms-conn-created.PNG?dl=0


Any help will be welcome.

Regards.

- WR

Reply via email to