2
votes

I am trying to connect Azure service bus from Java client with AMQP protocol

I follow the instruction in the following link:
http://azure.microsoft.com/en-us/documentation/articles/service-bus-java-how-to-use-jms-api-amqp/

1) created service bus in Azure portal with the name space 'availo' and a queue named 'queue1'
2) from service bus connection information I've got the following:

SharedAccessKeyName=RootManageSharedAccessKey
SharedAccessKey={key}

3) created "servicebus.properties" file for the JNDI lookup

   connectionfactory.SBCF = amqps://RootManageSharedAccessKey:encoded(key)@availo.servicebus.windows.net
   queue.QUEUE = queue1

4) below is my simple java main application with all the required jars (qpid) in the class path.

  public static void main(String[] args) {

    try {
        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.INITIAL_CONTEXT_FACTORY,
                "org.apache.qpid.amqp_1_0.jms.jndi.PropertiesFileInitialContextFactory");
        env.put(Context.PROVIDER_URL,
                "C:\\Users\\Assaf-PC\\Documents\\GitHub\\availo\\rest-api\\src\\main\\resources\\servicebus.properties");
        Context context = new InitialContext(env);
        // Lookup ConnectionFactory and Queue
        ConnectionFactory cf = (ConnectionFactory) context.lookup("SBCF");
        Destination queue = (Destination) context.lookup("QUEUE");
        // Create Connection
        Connection connection = cf.createConnection();
        // Create sender-side Session and MessageProducer
        Session sendSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producer = sendSession.createProducer(queue);
    } catch (Exception e) {
        e.getLocalizedMessage();
    }

}

When I run the program I am getting the exception below in the code line:

    MessageProducer producer = sendSession.createProducer(queue);

Exception:

Exception in thread "main" javax.jms.JMSException: Peer did not create remote endpoint for link, target: queue1
at org.apache.qpid.amqp_1_0.jms.impl.MessageProducerImpl.<init>(MessageProducerImpl.java:98)
at org.apache.qpid.amqp_1_0.jms.impl.SessionImpl.createProducer(SessionImpl.java:390)
at org.apache.qpid.amqp_1_0.jms.impl.SessionImpl.createProducer(SessionImpl.java:59)
at availo.rest.services.ServiceBus.main(ServiceBus.java:43)
  Caused by: org.apache.qpid.amqp_1_0.client.Sender$SenderCreationException: Peer did not create    remote endpoint for link, target: queue1
at org.apache.qpid.amqp_1_0.client.Sender.<init>(Sender.java:191)
at org.apache.qpid.amqp_1_0.client.Sender.<init>(Sender.java:119)
at org.apache.qpid.amqp_1_0.client.Sender.<init>(Sender.java:112)
at org.apache.qpid.amqp_1_0.client.Sender.<init>(Sender.java:98)
at org.apache.qpid.amqp_1_0.client.Sender.<init>(Sender.java:84)
at org.apache.qpid.amqp_1_0.client.Sender.<init>(Sender.java:78)
at org.apache.qpid.amqp_1_0.client.Session$1.<init>(Session.java:90)
at org.apache.qpid.amqp_1_0.client.Session.createSender(Session.java:89)
at org.apache.qpid.amqp_1_0.jms.impl.MessageProducerImpl.<init>(MessageProducerImpl.java:86)
... 3 more

Wasted many hours to understand what am I doing wrong without success can anyone help?
your answer is highly appreciated.

4
were you able to solve this problem? what was the solution if you can share??harishr

4 Answers

2
votes

Make sure your queue does not have partitioning enabled. ServiceBus does not support AMQP with partitioned queues, however queues are created with partitioning enabled by default.

I had this exact same error, and re-creating the queue with "Enable Partitioning" unchecked solved it for me.

See the Partitioned Entities Limitations section at the bottom of this article: https://msdn.microsoft.com/en-us/library/azure/dn520246.aspx

Partitioned queues and topics are only available via SBMP or HTTP/HTTPS. AMQP support will be added in the future.

1
votes

This answer is for beginners with Service Bus, like me.

First thing is to have Unpartitioned queue/topic for AMQP as partitioning is not supported like other answer said. We need to uncheck 'Enable Partitioning' while creating the queue from Azure Portal. By default entities are enabled with Partitioning in service bus.

Coming to the problem, I had the same problem when I was trying to use Java Client as Listener to the Queue using Qpid implementation of JMS with AMQP as in the example. The problem was that the Queue was not configured even though the ServiceBus was, in the Azure Portal.

Make sure you have added right configuration to your queue in the portal with right permissions and policy names, if you are planning to use different policyNames for sending-to/listening-from queue (See if this is helpful). The policyName OF THE QUEUE NOT SERVICE BUS, is the one to be used for SAS Authentication equivalent to username in ACS and primary/secondary key is equivalent to password in ACS in the config(servicebus.properties) file.

Try using Primary key first. If you get authentication error, then you can try the secondary key. If you have special characters in the key, like I had forwarded slash(/), replace it with corresponding UTF-8 value.So I had to use %2F to replace / in the key, in the config file.

That cleared my problems. Hope this helps!!

PTR(PointsToRemember):

  1. It is not suggested to use created from code to use for AMQP as in the current usecase. When you create a queue from code using Service Bus Java API, it is created with the partitioning enabled and no end point created FOR THE QUEUE. So, you'll end up with two exceptions,

    -- No end point created, as in the question of this context.

    --Once you go to portal configure it right in portal and in your config file, then you'd get 'AMQP not supported over Partitioned Entities' (You know this already!). So you have to go back and create a queue in portal again disabling partitioning and configure it. Kind of double work.. So better use the a queue thats create and configured right for AMQP.

  2. If you have special characters in the primary/secondary keys, you try regenerating them, instead of using them and replacing the special chars with corresponding UTF-8 in config file.
0
votes

as far as I can see the username / issuer name does not fit.

amqps://RootManageSharedAccessKey:encoded(key)@availo.servicebus.windows.net

should be:

amqps://owner:encoded(key)@availo.servicebus.windows.net

as the username from amqp is filled with the issuer name from the sb endpoint and that is "owner" per default (pls dbl check with your connection info of the azure sb)

Hope this helps.

Regards,

René

0
votes

Tip: when using a later version of Qpid (qpid-jms-client-0.11.1.jar), the connectionfactory property is different:

connectionfactory.myFactoryLookup = connectionfactory.myFactoryLookup = amqps://example-open-bus.servicebus.windows.net?amqp.idleTimeout=150000&jms.username=somePolicy&jms.password=aM2k3PaZY5jdIkmGKm7G%2FcH%2BUFQaFAgHIYc3dSkuiLI%3D 

see other post -> How can I Send/Receive a message from Azure Service Bus from Qpid JMS (qpid-jms-client-0.11.1.jar)?