We can generate the .bindings file for RabbitMQ using the following java code: import java.util.Properties;
import javax.jms.ConnectionFactory; import javax.jms.Queue; import javax.jms.Topic; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.Reference; import javax.naming.StringRefAddr; Properties env = new Properties(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory"); env.put(Context.PROVIDER_URL, "file:bindings"); Context ctx = new InitialContext(env); Reference connectionFactoryRef = new Reference(ConnectionFactory.class.getName(), RMQObjectFactory.class.getName(), null); connectionFactoryRef.add(new StringRefAddr("name", "jms/ConnectionFactory")); connectionFactoryRef.add(new StringRefAddr("type", ConnectionFactory.class.getName())); connectionFactoryRef.add(new StringRefAddr("factory", RMQObjectFactory.class.getName())); connectionFactoryRef.add(new StringRefAddr("host", "$JMS_RABBITMQ_HOST$")); connectionFactoryRef.add(new StringRefAddr("port", "$JMS_RABBITMQ_PORT$")); ctx.rebind("ConnectionFactory", connectionFactoryRef); String jndiAppend = "jndi"; for (int i = 1; i <= 10; i++) { String name = String.format("queue%02d", i); Reference ref = new Reference(Queue.class.getName(), com.rabbitmq.jms.admin.RMQObjectFactory.class.getName(), null); ref.add(new StringRefAddr("name", "jms/Queue")); ref.add(new StringRefAddr("type", Queue.class.getName())); ref.add(new StringRefAddr("factory", RMQObjectFactory.class.getName())); ref.add(new StringRefAddr("destinationName", name)); ctx.rebind(name+jndiAppend, ref); name = String.format("topic%02d", i); ref = new Reference(Topic.class.getName(), com.rabbitmq.jms.admin.RMQObjectFactory.class.getName(), null); ref.add(new StringRefAddr("name", "jms/Topic")); ref.add(new StringRefAddr("type", Topic.class.getName())); ref.add(new StringRefAddr("factory", RMQObjectFactory.class.getName())); ref.add(new StringRefAddr("destinationName", name)); ctx.rebind(name+jndiAppend, ref); }
source share