List of usage examples for com.rabbitmq.client Channel queueDeclare
Queue.DeclareOk queueDeclare() throws IOException;
From source file:org.apache.flume.amqp.AmqpConsumerTest.java
License:Apache License
@Test public void testDeclarationsForChannel_NoQueueNameAndBindings() throws Exception { AmqpConsumer consumer = builder.setQueueName(null).build(); AMQP.Queue.DeclareOk declareOk = mock(AMQP.Queue.DeclareOk.class); when(declareOk.getQueue()).thenReturn("queue"); Channel channel = mock(Channel.class); when(channel.queueDeclare()).thenReturn(declareOk); consumer.declarationsForChannel(channel); verify(channel).exchangeDeclare(EXCHANGE_NAME, Constants.AMQP.DIRECT_EXCHANGE, DURABLE_EXCHANGE); verify(channel).basicQos(PREFETCH_SIZE); verify(channel).queueDeclare();/*from w w w . j a v a2 s . c o m*/ verify(channel).queueBind("queue", EXCHANGE_NAME, BINDING_KEY_1); verify(channel).queueBind("queue", EXCHANGE_NAME, BINDING_KEY_2); }
From source file:org.apache.flume.amqp.AmqpConsumerTest.java
License:Apache License
@Test public void testDeclarationsForChannel_NoQueueNameAndNoBindings() throws Exception { AmqpConsumer consumer = builder.setQueueName(null).setBindings(new String[] {}).build(); AMQP.Queue.DeclareOk declareOk = mock(AMQP.Queue.DeclareOk.class); when(declareOk.getQueue()).thenReturn("queue"); Channel channel = mock(Channel.class); when(channel.queueDeclare()).thenReturn(declareOk); consumer.declarationsForChannel(channel); verify(channel).exchangeDeclare(EXCHANGE_NAME, Constants.AMQP.DIRECT_EXCHANGE, DURABLE_EXCHANGE); verify(channel).basicQos(PREFETCH_SIZE); verify(channel).queueDeclare();/*w w w.j ava2s . c o m*/ verify(channel).queueBind("queue", EXCHANGE_NAME, Constants.AMQP.SERVER_GENERATED_QUEUE_NAME); }
From source file:org.apache.helix.recipes.rabbitmq.ConsumerThread.java
License:Apache License
@Override public void run() { Connection connection = null; try {/* www . ja v a 2s . c om*/ ConnectionFactory factory = new ConnectionFactory(); factory.setHost(_mqServer); connection = factory.newConnection(); Channel channel = connection.createChannel(); channel.exchangeDeclare(EXCHANGE_NAME, "topic"); String queueName = channel.queueDeclare().getQueue(); String bindingKey = _partition.toString(); channel.queueBind(queueName, EXCHANGE_NAME, bindingKey); System.out.println( " [*] " + _consumerId + " Waiting for messages on " + bindingKey + ". To exit press CTRL+C"); QueueingConsumer consumer = new QueueingConsumer(channel); channel.basicConsume(queueName, true, consumer); while (true) { QueueingConsumer.Delivery delivery = consumer.nextDelivery(); String message = new String(delivery.getBody()); String routingKey = delivery.getEnvelope().getRoutingKey(); System.out.println(" [x] " + _consumerId + " Received '" + routingKey + "':'" + message + "'"); } } catch (InterruptedException e) { System.err.println(" [-] " + _consumerId + " on " + _partition + " is interrupted ..."); } catch (Exception e) { e.printStackTrace(); } finally { if (connection != null) { try { connection.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
From source file:org.axonframework.amqp.eventhandling.RabbitMQBenchmark.java
License:Apache License
public static void main(String[] args) throws IOException, InterruptedException, TimeoutException { final Connection connection = new ConnectionFactory().newConnection(); final Channel channel = connection.createChannel(); String queueName = channel.queueDeclare().getQueue(); execute("Transactional and Channel pooling", createChannelPoolSharingThreads(connection, queueName)); queueName = refreshQueue(channel, queueName); execute("Transactional, new Channel per tx", createChannelCreatingThreads(connection, queueName, true)); queueName = refreshQueue(channel, queueName); execute("Non-transactional, new Channel per tx", createChannelCreatingThreads(connection, queueName, false)); queueName = refreshQueue(channel, queueName); execute("Non-transactional, single Channel", createChannelSharingThreads(connection, queueName)); channel.confirmSelect();//w w w .j a v a 2s . co m connection.close(); }
From source file:org.axonframework.amqp.eventhandling.RabbitMQBenchmark.java
License:Apache License
private static String refreshQueue(Channel channel, String queueName) throws IOException { channel.queueDelete(queueName);/*from w w w . j a v a 2s . c o m*/ queueName = channel.queueDeclare().getQueue(); return queueName; }
From source file:org.axonframework.eventhandling.amqp.RabbitMQBenchmark.java
License:Apache License
public static void main(String[] args) throws IOException, InterruptedException { final Connection connection = new ConnectionFactory().newConnection(); final Channel channel = connection.createChannel(); String queueName = channel.queueDeclare().getQueue(); execute("Transactional and Channel pooling", createChannelPoolSharingThreads(connection, queueName)); queueName = refreshQueue(channel, queueName); execute("Transactional, new Channel per tx", createChannelCreatingThreads(connection, queueName, true)); queueName = refreshQueue(channel, queueName); execute("Non-transactional, new Channel per tx", createChannelCreatingThreads(connection, queueName, false)); queueName = refreshQueue(channel, queueName); execute("Non-transactional, single Channel", createChannelSharingThreads(connection, queueName)); channel.confirmSelect();//w w w. j av a2s . co m connection.close(); }
From source file:org.ballerinalang.messaging.rabbitmq.util.ChannelUtils.java
License:Open Source License
/** * Declares a queue with an auto-generated queue name. * * @param channel RabbitMQ Channel object. * @return An auto-generated queue name. *///from w w w. j a va 2 s .co m public static String queueDeclare(Channel channel) { try { return channel.queueDeclare().getQueue(); } catch (IOException exception) { String errorMessage = "An error occurred while auto-declaring the queue "; throw new BallerinaException(errorMessage + exception.getMessage(), exception); } }
From source file:org.mule.transport.amqp.AmqpEndpointUtil.java
License:Open Source License
public static String getOrCreateQueue(final Channel channel, final ImmutableEndpoint endpoint, final boolean activeDeclarationsOnly) throws IOException { final String exchangeName = getOrCreateExchange(channel, endpoint, activeDeclarationsOnly); final String routingKey = getRoutingKey(endpoint); if ((StringUtils.isBlank(exchangeName)) && (StringUtils.isNotBlank(routingKey))) { // no exchange name -> enforce routing key to be empty throw new MuleRuntimeException(MessageFactory.createStaticMessage( "An exchange name must be provided if a routing key is provided in endpoint: " + endpoint)); }/*from w w w . j a v a 2s .c o m*/ final String queueName = getQueueName(endpoint.getAddress()); if (StringUtils.isBlank(queueName)) { // no queue name -> create a private one on the server final DeclareOk queueDeclareResult = channel.queueDeclare(); final String privateQueueName = queueDeclareResult.getQueue(); LOG.info("Declared private queue: " + privateQueueName); bindQueue(channel, endpoint, exchangeName, routingKey, privateQueueName); return privateQueueName; } // queue name -> either create or ensure the queue exists if (endpoint.getProperties().containsKey(QUEUE_DURABLE) || endpoint.getProperties().containsKey(QUEUE_AUTO_DELETE) || endpoint.getProperties().containsKey(QUEUE_EXCLUSIVE)) { // any of the queue declaration parameter provided -> declare the queue final boolean queueDurable = BooleanUtils.toBoolean((String) endpoint.getProperty(QUEUE_DURABLE)); final boolean queueExclusive = BooleanUtils.toBoolean((String) endpoint.getProperty(QUEUE_EXCLUSIVE)); final boolean queueAutoDelete = BooleanUtils .toBoolean((String) endpoint.getProperty(QUEUE_AUTO_DELETE)); channel.queueDeclare(queueName, queueDurable, queueExclusive, queueAutoDelete, NO_ARGS); LOG.info("Declared queue: " + queueName + ", durable: " + queueDurable + ", exclusive: " + queueExclusive + ", autoDelete: " + queueAutoDelete); bindQueue(channel, endpoint, exchangeName, routingKey, queueName); } else if (!activeDeclarationsOnly) { // no declaration parameter -> ensure the queue exists channel.queueDeclarePassive(queueName); if (LOG.isDebugEnabled()) { LOG.debug("Validated presence of queue: " + queueName); } } return queueName; }
From source file:org.mule.transport.amqp.internal.client.AmqpDeclarer.java
License:Open Source License
public String declareTemporaryQueue(Channel channel) throws IOException { final AMQP.Queue.DeclareOk queueDeclareResult = channel.queueDeclare(); final String privateQueueName = queueDeclareResult.getQueue(); logger.debug("Declared private queue: " + privateQueueName); return privateQueueName; }
From source file:org.objectweb.proactive.extensions.amqp.remoteobject.FindQueuesRPCClient.java
License:Open Source License
@Override protected String createReplyQueue(Channel channel) throws IOException { return channel.queueDeclare().getQueue(); }