无法从外部连接到Jetty中嵌入的ActiveMQ代理

时间:2018-10-09 09:48:11

标签: java activemq

我有一个Jetty,它可以启动嵌入式ActiveMQ代理。我正在尝试使用JMSToolBox连接到它,但出现以下异常:

Transport Connection to: tcp://127.0.0.1:44523 failed: java.io.IOException: Unknown data type: 97

我的代码如下:

    File dataFileDir = new File("target/amq-in-action/kahadb");
    KahaDBStore kaha = new KahaDBStore();
    kaha.setDirectory(dataFileDir);
    kaha.setJournalMaxFileLength(1024 * 1204 * 100);
    kaha.setIndexWriteBatchSize(100);
    kaha.setEnableIndexWriteAsync(false);

    List<AuthenticationUser> users = new ArrayList<AuthenticationUser>();
    users.add(new AuthenticationUser(USER_NAME, PWD, "users,users_write"));
    SimpleAuthenticationPlugin simpleAuthenticationPlugin = new SimpleAuthenticationPlugin(users);
    simpleAuthenticationPlugin.setAnonymousAccessAllowed(false);

    List<DestinationMapEntry> authorizationEntries = new ArrayList<>();
    // giving permission to read the queue for users groups 
    AuthorizationEntry authorizationEntry = new AuthorizationEntry();
    authorizationEntry.setRead("users");
    authorizationEntry.setWrite("admins,users_write");
    authorizationEntry.setAdmin("admins");
    authorizationEntry.setQueue("Provisioning");
    authorizationEntries.add(authorizationEntry);
    // "Note that full access rights should generally be given to the ActiveMQ.Advisory destinations because by default an ActiveMQConnection uses destination advisors to get early knowledge of temp destination creation and deletion." -> http://activemq.apache.org/security.html
    authorizationEntry = new AuthorizationEntry();
    authorizationEntry.setRead("guests,users");
    authorizationEntry.setWrite("guests,users");
    authorizationEntry.setAdmin("guests,users");
    authorizationEntry.setTopic("ActiveMQ.Advisory.>");
    authorizationEntries.add(authorizationEntry);       
    AuthorizationMap authorizationMap = new DefaultAuthorizationMap(authorizationEntries);
    AuthorizationPlugin authorizationPlugin = new AuthorizationPlugin(authorizationMap);

    // creating the broker service
    broker = new BrokerService();
    broker.setPersistenceAdapter(kaha);
    broker.setUseJmx(false);
    broker.setPlugins(new BrokerPlugin[]{simpleAuthenticationPlugin, authorizationPlugin});
    broker.addConnector("tcp://localhost:61616");

    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
    new Resource(null, "java:/ConnectionFactory", connectionFactory);
    broker.start();

我想我应该能够从外部工具连接到嵌入式队列。
有想法吗?

谢谢,
V。

1 个答案:

答案 0 :(得分:0)

对于JMSToolBox,JMX必须处于活动状态,因此请进行更改 broker.setUseJmx(false);
broker.setUseJmx(true); // This is the default..

另外,您可能会对this JMSToolBox issue中有一个正在运行的示例感兴趣

丹尼斯