@Grab(group='com.rabbitmq', module='amqp-client', version='2.6.1') import com.rabbitmq.client.* factory = new ConnectionFactory() factory.host = "localhost" connection = factory.newConnection() channel = connection.createChannel() // topic exchangeを作成 exchangeName = "my_topic_exchange" channel.exchangeDeclare(exchangeName, "topic") // queueを作成&bind queueName1 = "groovy_all_queue" channel.queueDeclare(queueName1, true /*= durable */, false/*= exclusive*/, false /*= autoDelete*/, null /*= arguments */) channel.queueBind(queueName1, exchangeName, "groovy.#") queueName2 = "groovy_news_queue" channel.queueDeclare(queueName2, true /*= durable */, false/*= exclusive*/, false /*= autoDelete*/, null /*= arguments */) channel.queueBind(queueName2, exchangeName, "groovy.news.#") // メッセージを送信 channel.basicPublish(exchangeName, "groovy.info", MessageProperties.PERSISTENT_TEXT_PLAIN, "groovyの情報".getBytes("UTF-8")) // メッセージを送信 channel.basicPublish(exchangeName, "groovy.news.release", MessageProperties.PERSISTENT_TEXT_PLAIN, "new version is released!".getBytes("UTF-8")) channel.close() connection.close()メッセージを受信するにはgroovyとrabbitmqでメッセージの送信・受信をおこなうの受信プログラムと同様にgroovy_all_queue, groovy_news_queueをコマンドライン引数に指定します。
動作環境
groovy 1.8.2, JDK6 Update26, rabbitmq 2.6.1
0 件のコメント:
コメントを投稿