com.rabbitmq.client.Channel.queueDeclare()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(231)

本文整理了Java中com.rabbitmq.client.Channel.queueDeclare()方法的一些代码示例,展示了Channel.queueDeclare()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Channel.queueDeclare()方法的具体详情如下:
包路径:com.rabbitmq.client.Channel
类名称:Channel
方法名:queueDeclare

Channel.queueDeclare介绍

暂无

代码示例

代码示例来源:origin: apache/flink

/**
 * Sets up the queue. The default implementation just declares the queue. The user may override
 * this method to have a custom setup for the queue (i.e. binding the queue to an exchange or
 * defining custom queue parameters)
 */
protected void setupQueue() throws IOException {
  if (queueName != null) {
    channel.queueDeclare(queueName, false, false, false, null);
  }
}

代码示例来源:origin: apache/flink

/**
 * Sets up the queue. The default implementation just declares the queue. The user may override
 * this method to have a custom setup for the queue (i.e. binding the queue to an exchange or
 * defining custom queue parameters)
 */
protected void setupQueue() throws IOException {
  channel.queueDeclare(queueName, true, false, false, null);
}

代码示例来源:origin: Graylog2/graylog2-server

channel.queueDeclare(queueName, true, false, false, null);
if (exchangeBind) {
  channel.queueBind(queueName, exchange, routingKey);

代码示例来源:origin: testcontainers/testcontainers-java

@Test
public void simpleRabbitMqTest() throws IOException, TimeoutException {
  ConnectionFactory factory = new ConnectionFactory();
  factory.setHost(rabbitMq.getContainerIpAddress());
  factory.setPort(rabbitMq.getMappedPort(RABBITMQ_PORT));
  Connection connection = factory.newConnection();
  Channel channel = connection.createChannel();
  channel.exchangeDeclare(RABBIQMQ_TEST_EXCHANGE, "direct", true);
  String queueName = channel.queueDeclare().getQueue();
  channel.queueBind(queueName, RABBIQMQ_TEST_EXCHANGE, RABBITMQ_TEST_ROUTING_KEY);
  // Set up a consumer on the queue
  final boolean[] messageWasReceived = new boolean[1];
  channel.basicConsume(queueName, false, new DefaultConsumer(channel) {
    @Override
    public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
      messageWasReceived[0] = Arrays.equals(body, RABBITMQ_TEST_MESSAGE.getBytes());
    }
  });
  // post a message
  channel.basicPublish(RABBIQMQ_TEST_EXCHANGE, RABBITMQ_TEST_ROUTING_KEY, null, RABBITMQ_TEST_MESSAGE.getBytes());
  // check the message was received
  assertTrue("The message was received", Unreliables.retryUntilSuccess(5, TimeUnit.SECONDS, () -> {
    if (!messageWasReceived[0]) {
      throw new IllegalStateException("Message not received yet");
    }
    return true;
  }));
}

代码示例来源:origin: yacy/yacy_grid_mcp

private void connect() throws IOException {
    Map<String, Object> arguments = new HashMap<>();
    arguments.put("x-queue-mode", "lazy"); // we want to minimize memory usage; see http://www.rabbitmq.com/lazy-queues.html
    boolean lazys = lazy.get();
    try {
      RabbitQueueFactory.this.channel.queueDeclare(this.queueName, true, false, false, lazys ? arguments : null);
    } catch (AlreadyClosedException e) {
      lazys = !lazys;
      try {
        channel = connection.createChannel();
        // may happen if a queue was previously not declared "lazy". So we try non-lazy queue setting now.
        RabbitQueueFactory.this.channel.queueDeclare(this.queueName, true, false, false, lazys ? arguments : null);
        // if this is successfull, set the new lazy value
        lazy.set(lazys);
      } catch (AlreadyClosedException ee) {
        throw new IOException(ee.getMessage());
      }
  }
}

代码示例来源:origin: apache/incubator-druid

channel.queueDeclare(queue, durable, exclusive, autoDelete, null);
channel.queueBind(queue, exchange, routingKey);
channel.addShutdownListener(

代码示例来源:origin: zstackio/zstack

public void construct() {
  try {
    eventChan = conn.createChannel();
    eventChan.queueDeclare(queueName, false, false, true, queueArguments());
    eventChan.basicConsume(queueName, true, this);
  } catch (IOException e) {
    throw new CloudRuntimeException(e);
  }
}

代码示例来源:origin: zstackio/zstack

public void construct() {
  try {
    nrouteChan = conn.createChannel();
    nrouteChan.queueDeclare(nrouteName, false, false, true, null);
    nrouteChan.queueBind(nrouteName, BusExchange.NO_ROUTE.toString(), "");
    nrouteChan.basicConsume(nrouteName, true, this);
  } catch (IOException e) {
    throw new CloudRuntimeException(e);
  }
}

代码示例来源:origin: vector4wang/spring-boot-quick

public static void main(String[] args) {
    try {
      ConnectionFactory factory = new ConnectionFactory();
      factory.setUsername("guest");
      factory.setPassword("guest");
      factory.setHost("60.205.191.82");
      factory.setPort(5672);
      Connection conn = factory.newConnection();
      Channel channel = conn.createChannel();

//            channel.qu
      channel.queueDeclare("hello", false, false, false, null);
      String message = "Hello World!";
      channel.basicPublish("", "hello", null, message.getBytes());
      System.out.println(" [x] Sent '" + message + "'");

      channel.close();
      conn.close();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (TimeoutException e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: zstackio/zstack

void init() {
  try {
    ConnectionFactory connFactory = new ConnectionFactory();
    List<Address> addresses = CollectionUtils.transformToList(bus.getServerIps(), new Function<Address, String>() {
      @Override
      public Address call(String arg) {
        return Address.parseAddress(arg);
      }
    });
    conn = connFactory.newConnection(addresses.toArray(new Address[]{}));
    chan = conn.createChannel();
    String name = MessageTracker.class.getName();
    chan.queueDeclare(name, true, false, true, null);
    chan.basicConsume(name, true, this);
    chan.queueBind(name, BusExchange.P2P.toString(), "#");
    chan.queueBind(name, BusExchange.BROADCAST.toString(), "#");
  } catch (Exception e) {
    throw new CloudRuntimeException(e);
  }
}

代码示例来源:origin: spring-projects/spring-amqp

@Override
public com.rabbitmq.client.AMQP.Queue.DeclareOk queueDeclare()
    throws IOException {
  return this.delegate.queueDeclare();
}

代码示例来源:origin: spring-projects/spring-amqp

@Override
public com.rabbitmq.client.AMQP.Queue.DeclareOk queueDeclare(String queue,
    boolean durable, boolean exclusive, boolean autoDelete,
    Map<String, Object> arguments) throws IOException {
  return this.delegate.queueDeclare(queue, durable, exclusive, autoDelete,
      arguments);
}

代码示例来源:origin: zstackio/zstack

chan.queueDeclare(name, false, false, true, null);
chan.basicConsume(name, true, tracker);
chan.queueBind(name, BusExchange.BROADCAST.toString(), "#");

代码示例来源:origin: spring-projects/spring-integration

@SuppressWarnings("unchecked")
@Test
public void testPtP() throws Exception {
  final Channel channel = mock(Channel.class);
  DeclareOk declareOk = mock(DeclareOk.class);
  when(declareOk.getQueue()).thenReturn("noSubscribersChannel");
  when(channel.queueDeclare(anyString(), anyBoolean(), anyBoolean(), anyBoolean(), isNull()))
      .thenReturn(declareOk);
  Connection connection = mock(Connection.class);
  doAnswer(invocation -> channel).when(connection).createChannel(anyBoolean());
  ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
  when(connectionFactory.createConnection()).thenReturn(connection);
  SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
  container.setConnectionFactory(connectionFactory);
  AmqpTemplate amqpTemplate = mock(AmqpTemplate.class);
  PointToPointSubscribableAmqpChannel amqpChannel =
      new PointToPointSubscribableAmqpChannel("noSubscribersChannel", container, amqpTemplate);
  amqpChannel.setBeanName("noSubscribersChannel");
  amqpChannel.setBeanFactory(mock(BeanFactory.class));
  amqpChannel.afterPropertiesSet();
  MessageListener listener = (MessageListener) container.getMessageListener();
  try {
    listener.onMessage(new Message("Hello world!".getBytes(), null));
    fail("Exception expected");
  }
  catch (MessageDeliveryException e) {
    assertThat(e.getMessage(),
        containsString("Dispatcher has no subscribers for amqp-channel 'noSubscribersChannel'."));
  }
}

代码示例来源:origin: zstackio/zstack

outboundQueue = new BusQueue(makeMessageQueueName(SERVICE_ID), BusExchange.P2P);
Channel chan = channelPool.acquire();
chan.queueDeclare(outboundQueue.getName(), false, false, true, queueArguments());
chan.basicConsume(outboundQueue.getName(), true, consumer);
chan.queueBind(outboundQueue.getName(), outboundQueue.getBusExchange().toString(), outboundQueue.getBindingKey());

代码示例来源:origin: com.intrbiz.bergamot/bergamot-queue

protected String setupQueue(Channel on) throws IOException
{
  String queueName = on.queueDeclare().getQueue();
  on.exchangeDeclare("bergamot.update", "topic", true);
  on.queueBind(queueName, "bergamot.update", (site == null ? "*" : site.toString()) + "." + (check == null ? "*" : check.toString()));
  return queueName;
}

代码示例来源:origin: com.intrbiz.bergamot/bergamot-queue

public String setupQueue(Channel on) throws IOException
  {
    on.queueDeclare("bergamot.reading.fallback_queue", true, false, false, null);
    on.exchangeDeclare("bergamot.reading.fallback", "fanout", true, false, null);
    on.queueBind("bergamot.reading.fallback_queue", "bergamot.reading.fallback", "");
    return "bergamot.reading.fallback_queue";
  }
};

代码示例来源:origin: com.intrbiz.bergamot/bergamot-queue

public String setupQueue(Channel on) throws IOException
  {
    // exchange
    on.exchangeDeclare("bergamot.notification", "topic", true);
    // queue
    String queueName = on.queueDeclare().getQueue();
    // bind using the site
    on.queueBind(queueName, "bergamot.notification", site == null ? "#" : site.toString());
    return queueName;
  }
};

代码示例来源:origin: imalexyang/ExamStack

@Bean
QueueingConsumer queueingConsumer() throws IOException {
  ConnectionFactory factory = new ConnectionFactory();
  factory.setHost(messageQueueHostname);
  Connection connection = factory.newConnection();
  Channel channel = connection.createChannel();
  channel.queueDeclare(Constants.ANSWERSHEET_DATA_QUEUE, true, false, false, null);
  QueueingConsumer consumer = new QueueingConsumer(channel);
  channel.basicConsume(Constants.ANSWERSHEET_DATA_QUEUE, true, consumer);
  return consumer;
}

代码示例来源:origin: addthis/hydra

@Override public void open() throws IOException {
  getChannel().exchangeDeclare(exchange, "direct");
  getChannel().queueDeclare(queueName, true, false, false, null);
  for (String routingKey : routingKeys) {
    getChannel().queueBind(queueName, exchange, routingKey);
  }
  getChannel().basicConsume(queueName, false, this);
}

相关文章

微信公众号

最新文章

更多