How to embed broker? Missing broker.xml

非 Y 不嫁゛ 提交于 2020-06-29 06:44:16

问题


Currently I am writing a class which shall start and configure an embedded JMS server and after that mediate between Producers and Consumers.

I found this reference and it says that it needs a broker.xml but doesn't supply any example. Can somebody tell me what I need to put into the file.

And also: Will it work to start the BrokerServer as I imagine?

EDIT:

Now I use this code:

...

        SecurityConfiguration securityConfig = new SecurityConfiguration();
        securityConfig.addUser("guest", "guest");
        securityConfig.addRole("guest", "guest");
        securityConfig.setDefaultUser("guest");
        ActiveMQJAASSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), securityConfig);

        // Step 2. Create and start embedded broker.
        ActiveMQServer server = null;
        try {
            server = ActiveMQServers.newActiveMQServer("broker.xml", null, securityManager);
            server.start();
            System.out.println("Started Embedded Broker");
        } catch (Exception e) {
            e.printStackTrace();
        }
...

But I receive the error:

java.net.MalformedURLException: no protocol: broker.xml

Even so the the file is right next to the class. Where does the file has to be?

broker.xml

<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:activemq" xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd">
   <core xmlns="urn:activemq:core">

      <persistence-enabled>false</persistence-enabled>

      <acceptors>
         <acceptor name="in-vm">vm://0</acceptor>
      </acceptors>

      <security-settings>
         <security-setting match="#">
            <permission type="createAddress" roles="guest"/>
            <permission type="createDurableQueue" roles="guest"/>
            <permission type="deleteDurableQueue" roles="guest"/>
            <permission type="createNonDurableQueue" roles="guest"/>
            <permission type="deleteNonDurableQueue" roles="guest"/>
            <permission type="consume" roles="guest"/>
            <permission type="send" roles="guest"/>
         </security-setting>
      </security-settings>
   </core>
</configuration>

回答1:


The documentation you cited actually covers 2 different ways to embed an instance of ActiveMQ Artemis. The first way uses a broker.xml on your classpath. The second way just uses the configuration API (i.e. programmatic configuration without XML config).

ActiveMQ Artemis ships with many examples in the examples directory demonstrating all kinds of ways to configure the broker via broker.xml. There are even 2 examples demonstrating the two different ways to embed the broker as discussed in the documentation. Check out the example in examples/features/standard/embedded-simple for a demonstration of how to embed a broker and use a broker.xml on the classpath for configuration. Check out the example in examples/features/standard/embedded for a demonstration of how to embed a broker and configure it programmatically.



来源:https://stackoverflow.com/questions/62431011/how-to-embed-broker-missing-broker-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!