接続からDestinationSourceを使用して、使用可能なキューのリストを取得できます。
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
ActiveMQConnection connection = (ActiveMQConnection)connectionFactory.createConnection();
DestinationSource ds = connection.getDestinationSource();
Set<ActiveMQQueue> queues = ds.getQueues();
編集:キューを作成するには、ActiveMQ Hello worldサンプルリンクを参照してください。コードは、jvmに埋め込まれたactiveMQブローカーへの接続を作成しています。
// Create a ConnectionFactory
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
// Create a Connection
Connection connection = connectionFactory.createConnection();
connection.start();
// Create a Session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create the destination (Topic or Queue)
Destination destination = session.createQueue("TEST.FOO");
上記のコードでは明らかではないかもしれないことは、次の行です。
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
ブローカーへの接続をセットアップするだけでなく、ブローカーがまだない場合は接続内にブローカーを埋め込みます。このページの下部で説明されています
その機能は使用をオフにすることができます(ブローカーが必要ですが、他の方法で設定したい場合):
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?create=false");
私はActiveMQが本当に好きですが、永続性以上のものを提供するため、単純なことを行うと、物事が少し複雑に見えるかもしれません。しかし、それがあなたを怖がらせないことを願っています。