How do I set up a security provider in Qpid to all

2019-08-14 05:04发布

This is my first day with Apache Proton and Qpid (java-broker version 0.32) and I need a simple send and receive example in Java (no JMS). By poking around I found Send.java and Recv.java neither of which actually work.

On "mng.send() I get

java.io.IOException: An established connection was aborted by the software in your host machine

From stackoverflow and a half dozen other google searches it seems that one must create an "anonymous" security provider first.

How does one do this? I can't guess either the config.json change nor how to use the web interface. The two sentences of prose in the Qpid java broker documentation are not helping me.

On a related note, couldn't I just use "amqp://admin:admin@localhost:5672" (or amqps://admin:admin@localhost ?) and take advantage of the security provider that is already there?

Does anyone have a documented Java example of Send and Recv that is known to actually run on the current version of Qpid and Proton and comes with any prerequisite config.json changes?

标签: java amqp qpid
3条回答
地球回转人心会变
2楼-- · 2019-08-14 05:12

To enable ANONYMOUS authentication, add an empty anonymous-auth-manager tag in the security section of your broker config:

<security>
  <anonymous-auth-manager/>
  ...
</security>

default location is ${QPID_HOME}/etc/config.xml

查看更多
疯言疯语
3楼-- · 2019-08-14 05:19

QPID Java Broker with QPID Proton library works without error for anonymous authentication.

Please follow below steps to avoid connection abort for QPID Java Broker 0.32.

  1. Log on to Broker local web page e.g. locahost:8080 with your admin user and password
  2. Go to "Broker" tab and scroll down to locate "Authentication Providers"
  3. And click "Add Provider" enter following details and save, Name: anonymous Type: Anonymous

  4. Now again, go to "Broker" tab and scroll down to locate "Ports" - AMQP. Click AMQP to edit. Select "Authentication Provider" to the one you have created in step #3 above from the drop-down and save.

  5. Try your test code

Here is the working sample in case required:

private static final String address = "amqp://guest:guest@localhost:5672/"; // (format : QPIDPortName://user:password@host:port you may use admin:admin as well if not removed from default setting by your administrator) 
private static final String exchangeName = "MYTOPIC-EXCHANGE"; // First create this exchange in QPID Broker!
private static final String publishToAddress = new StringBuilder().append(address).append(exchangeName).toString();

public static boolean publishMessage(String msg)
{
    boolean isMsgDelivered = false;
    ApplicationProperties customAppProperties = null;
    try 
    {
        Messenger messenger = Proton.messenger();
        messenger.start();
        Message message = Proton.message();

        message.setAddress(publishToAddress);
        message.setContentEncoding("UTF-8");
        message.setContentType("text/plain");
        message.setSubject(exchangeName);
        Section sec = new AmqpValue(msg);
        message.setBody(sec);

        messenger.put(message);
        messenger.send();
        messenger.stop();
        isMsgDelivered = true;
    } 
    catch (Exception e) 
    {
        logger.log(Level.SEVERE, "Qpid Proton error: "+ e.getMessage(), e);
        e.printStackTrace();
    }

    return isMsgDelivered;
}
查看更多
冷血范
4楼-- · 2019-08-14 05:25

The Java broker does not support anonymous authentication. I need to switch to the C++ broker.

Qid and Proton still needs a Java tutorial if only so the qpid team can test it.

查看更多
登录 后发表回答