Using ActiveMQ via JNDI

前端 未结 2 1230
情话喂你
情话喂你 2021-01-02 19:49

I\'m trying to create simply connect with ActiveMQ using JNDI.


I have

  1. Queue named \'example.A\'.

  2. According ActiveMQ documentation touc

2条回答
  •  暖寄归人
    2021-01-02 20:35

    You can set static properties as well as retrieve them from a file as such:

        InputStream is = getClass().getResourceAsStream("/my.jndi.properties");
        Properties jndiParameters = new Properties();
        jndiParameters.load(is);
        jndiParameters.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
        jndiParameters.put(Context.PROVIDER_URL, "tcp://localhost:61616");
        Context ctx =  new InitialContext(jndiParameters);
    ...
    

    This works as long as you set the static props after you load the resource. Helpful if you're loading the provider url from somewhere else for instance.

提交回复
热议问题