且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Qpid中设置安全提供程序以允许匿名身份验证以及名称/密码身份验证?

更新时间:2023-12-01 07:49:45

带有QPID Proton库的QPID Java Broker可以正确进行匿名身份验证.

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

请按照以下步骤操作,以避免QPID Java Broker 0.32的连接中止.

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

  1. 登录到Broker本地网页,例如locahost:8080,使用您的管理员用户名和密码
  2. 转到代理"标签,然后向下滚动以找到身份验证提供程序"
  3. 并单击添加提供者",输入以下详细信息并保存, 名称:匿名 类型:匿名

  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

现在,再次转到代理"选项卡,然后向下滚动以找到端口"-AMQP.单击AMQP进行编辑.从下拉菜单中选择您在上面的步骤3中创建的身份验证提供程序",然后保存.

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.

尝试您的测试代码

在需要的情况下,这里是工作样本:

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;
}