Example usage for org.springframework.amqp.core BindingBuilder bind

List of usage examples for org.springframework.amqp.core BindingBuilder bind

Introduction

In this page you can find the example usage for org.springframework.amqp.core BindingBuilder bind.

Prototype

public static DestinationConfigurer bind(Exchange exchange) 

Source Link

Usage

From source file:com.mtech.easyexchange.ordersolver.OrderSolverConfigurer.java

public static void main(String... args) throws Exception {

    ConnectionFactory cf = new CachingConnectionFactory("127.0.0.1");

    RabbitAdmin admin = new RabbitAdmin(cf);

    Queue queue = new Queue("OrderQueue");
    admin.declareQueue(queue);/*from   w  w w  .  ja va 2 s  . c  o m*/

    TopicExchange exchange = new TopicExchange("OrderExchange");
    admin.declareExchange(exchange);

    admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("*"));

    OrderMessageHolder holder = new OrderMessageHolder();

    OrderSolverThread ost = new OrderSolverThread(holder);
    ost.start();

    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cf);
    container.setMessageListener(new OrderMessageConsumer(holder));
    container.setQueueNames("OrderQueue");
    container.start();
}

From source file:com.anton.dev.tqrbs2.basic.BasicJava.java

public static void main(String[] args) throws Exception {
    ConnectionFactory cf = new CachingConnectionFactory();

    // set up the queue, exchange, binding on the broker
    RabbitAdmin admin = new RabbitAdmin(cf);
    Queue queue = new Queue("myQueue");
    admin.declareQueue(queue);//from  www .  ja v a  2 s.  c om
    TopicExchange exchange = new TopicExchange("myExchange2");
    admin.declareExchange(exchange);
    admin.declareBinding(BindingBuilder.bind(queue).to(exchange).with("foo.*"));

    // set up the listener and container
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(cf);
    Object listener = new Object() {
        public void handleMessage(String foo) {
            LOGGER.info("Recibiendo Java: " + foo);
        }
    };
    MessageListenerAdapter adapter = new MessageListenerAdapter(listener);
    container.setMessageListener(adapter);
    container.setQueueNames("myQueue");
    container.start();

    // send something
    RabbitTemplate template = new RabbitTemplate(cf);
    String msg = "Hello, world Rabbit!";
    LOGGER.info("Enviando Java: " + msg);
    template.convertAndSend("myExchange2", "foo.bar", msg);
    Thread.sleep(1000);
    container.stop();
}

From source file:com.xoom.rabbit.test.Main.java

public static void main(String[] args) throws InterruptedException {
    if (args.length != 9) {
        System.out.println(/*from   ww  w  .  j a  v  a2s. co  m*/
                "usage: java -jar target/rabbit-tester-0.1-SNAPSHOT-standalone.jar [consumer_threads] [number_of_messages] [amqp_host] [amqp_port] [produce] [consume] [message size in bytes] [username] [password]");
        return;
    }
    final long startTime = System.currentTimeMillis();
    int consumerThreads = Integer.parseInt(args[0]);
    final int messages = Integer.parseInt(args[1]);
    String host = args[2];
    int port = Integer.parseInt(args[3]);
    boolean produce = Boolean.parseBoolean(args[4]);
    boolean consume = Boolean.parseBoolean(args[5]);
    final int messageSize = Integer.parseInt(args[6]);
    String username = args[7];
    String password = args[8];

    if (produce) {
        System.out.println("Sending " + messages + " messages to " + host + ":" + port);
    }
    if (consume) {
        System.out.println("Consuming " + messages + " messages from " + host + ":" + port);
    }
    if (!produce && !consume) {
        System.out.println("Not producing or consuming any messages.");
    }

    CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host, port);
    connectionFactory.setUsername(username);
    connectionFactory.setPassword(password);
    connectionFactory.setChannelCacheSize(consumerThreads + 1);

    RabbitAdmin amqpAdmin = new RabbitAdmin(connectionFactory);

    DirectExchange exchange = new DirectExchange(EXCHANGE_NAME, true, false);
    Queue queue = new Queue(QUEUE_NAME);
    amqpAdmin.declareExchange(exchange);
    amqpAdmin.declareQueue(queue);
    amqpAdmin.declareBinding(BindingBuilder.bind(queue).to(exchange).with(ROUTING_KEY));

    final AmqpTemplate amqpTemplate = new RabbitTemplate(connectionFactory);

    final CountDownLatch producerLatch = new CountDownLatch(messages);
    final CountDownLatch consumerLatch = new CountDownLatch(messages);

    SimpleMessageListenerContainer listenerContainer = null;

    if (consume) {
        listenerContainer = new SimpleMessageListenerContainer();
        listenerContainer.setConnectionFactory(connectionFactory);
        listenerContainer.setQueueNames(QUEUE_NAME);
        listenerContainer.setConcurrentConsumers(consumerThreads);
        listenerContainer.setMessageListener(new MessageListener() {
            @Override
            public void onMessage(Message message) {
                if (consumerLatch.getCount() == 1) {
                    System.out.println("Finished consuming " + messages + " messages in "
                            + (System.currentTimeMillis() - startTime) + "ms");
                }
                consumerLatch.countDown();
            }
        });
        listenerContainer.start();
    }

    if (produce) {
        while (producerLatch.getCount() > 0) {
            try {
                byte[] message = new byte[messageSize];
                RND.nextBytes(message);
                amqpTemplate.send(EXCHANGE_NAME, ROUTING_KEY, new Message(message, new MessageProperties()));
                producerLatch.countDown();
            } catch (Exception e) {
                System.out.println("Failed to send message " + (messages - producerLatch.getCount())
                        + " will retry forever.");
            }
        }
    }

    if (consume) {
        consumerLatch.await();
        listenerContainer.shutdown();
    }

    connectionFactory.destroy();
}

From source file:io.curly.tagger.config.AmqpConfiguration.java

@Bean
Binding binding(TopicExchange artifactoryExchange, Queue tagQueue) {
    return BindingBuilder.bind(tagQueue).to(artifactoryExchange).with(tagQueue.getName());
}

From source file:io.curly.advisor.integration.config.AmqpConfiguration.java

@Bean
Binding notificationBinding(Queue notificationQueue, TopicExchange notificationExchange) {
    return BindingBuilder.bind(notificationQueue).to(notificationExchange).with(notificationQueue.getName());
}

From source file:io.curly.gathering.AmqpConfiguration.java

@Bean
Binding notificationBinding(Queue notificationQueue, TopicExchange notificationExchange) {
    return BindingBuilder.bind(notificationQueue).to(notificationExchange)
            .with(Constants.Amqp.MENTION_NOTIF_QUEUE);
}

From source file:de.msg.message.amqp.AmqpConfiguration.java

@Bean
public Binding binding(Queue queue, TopicExchange exchange) {
    return BindingBuilder.bind(queue).to(exchange).with(QUEUE_NAME);
}

From source file:com.anton.dev.tqrbs2.QueuePublishProcess.java

private void setup() {
    Exchange exchange = DirectExchange.DEFAULT;
    boolean durable = true;

    for (int i = 1; i <= 5; i++) {
        String queueName = "test.queue." + i;
        Queue q = new Queue(queueName, durable, false, true);
        admin.declareQueue(q);/*from  ww w  .j av  a  2  s.  c om*/
        BindingBuilder.bind(q).to(exchange).with(queueName);
        LOGGER.info("Bounded queue " + queueName);
    }
}

From source file:io.curly.artifact.integration.config.AmqpConfiguration.java

@Bean
Binding tagBinding(TopicExchange exchange, Queue tagQueue) {
    return BindingBuilder.bind(tagQueue).to(exchange).with(tagQueue.getName());
}

From source file:io.curly.artifact.integration.config.AmqpConfiguration.java

@Bean
Binding notifierBinding(TopicExchange notificationExchange, Queue notifierQueue) {
    return BindingBuilder.bind(notifierQueue).to(notificationExchange).with(notifierQueue.getName());
}