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?
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.
- Log on to Broker local web page e.g. locahost:8080 with your admin user and password
- Go to "Broker" tab and scroll down to locate "Authentication Providers"
And click "Add Provider" enter following details and save,
Name: anonymous
Type: Anonymous
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.
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;
}
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
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.