本文整理了Java中com.rabbitmq.client.Channel.queueDeclarePassive()
方法的一些代码示例,展示了Channel.queueDeclarePassive()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Channel.queueDeclarePassive()
方法的具体详情如下:
包路径:com.rabbitmq.client.Channel
类名称:Channel
方法名:queueDeclarePassive
暂无
代码示例来源:origin: yacy/yacy_grid_mcp
private int availableInternal() throws IOException {
return channel.queueDeclarePassive(this.queueName).getMessageCount();
}
}
代码示例来源:origin: org.apache.axis2.transport/axis2-transport-rabbitmq-amqp
public static boolean isQueueAvailable(Channel channel, String queueName) throws IOException {
try {
// check availability of the named queue
// if an error is encountered, including if the queue does not exist and if the
// queue is exclusively owned by another connection
channel.queueDeclarePassive(queueName);
return true;
} catch (IOException e) {
return false;
}
}
代码示例来源:origin: spring-projects/spring-amqp
@Override
public com.rabbitmq.client.AMQP.Queue.DeclareOk queueDeclarePassive(
String queue) throws IOException {
return this.delegate.queueDeclarePassive(queue);
}
代码示例来源:origin: org.springframework.amqp/spring-rabbit
@Override
public com.rabbitmq.client.AMQP.Queue.DeclareOk queueDeclarePassive(
String queue) throws IOException {
return this.delegate.queueDeclarePassive(queue);
}
代码示例来源:origin: meltwater/rxrabbit
@Override
public AMQP.Queue.DeclareOk queueDeclarePassive(String queue) throws IOException {
return delegate.queueDeclarePassive(queue);
}
代码示例来源:origin: yanghua/banyan
/**
* for other function, it borrow a outer channel
*
* @param queueName
* @param outerChannel
* @return
*/
private boolean innerExists(String queueName, Channel outerChannel) {
boolean result = true;
try {
outerChannel.queueDeclarePassive(queueName);
} catch (IOException e) {
result = false;
}
return result;
}
代码示例来源:origin: rabbitmq/rabbitmq-jms-client
private static int getNumberOfMessages(Channel channel, String destQueueName) {
try {
// It turns out that the messages take an indeterminate time to get to their queues,
// so this passive declare may not give a result that agrees with our expectations
// (even though it is *accurate* in some rabbitmq-server defined sense).
// Heuristics, like issuing the passive declare twice in a row, with or without a pause,
// do not always work---there appear to be some erratic delays occasionally---and so
// the decision has been taken to *not* try to circumvent this. There is, after all,
// nothing in the JMS spec that makes any guarantees about what a QueueBrowser will see.
// Our integration tests have to be less dogmatic, therefore.
// In the code below, there are commented out sections used in test to explore the behaviour.
// int mc1 = channel.queueDeclarePassive(destQueueName).getMessageCount();
// Thread.sleep(100);
int mc2 = channel.queueDeclarePassive(destQueueName).getMessageCount();
// if (mc1!=mc2) System.out.println(String.format("q='%s', msgcount=%s/%s", destQueueName, mc1, mc2));
// System.out.println(String.format("q='%s', msgcount=%s", destQueueName, mc2));
return mc2;
} catch (Exception e) { // ignore errors---we assume no messages in the queue in this case.
}
return 0; // default drop-through value
}
代码示例来源:origin: yanghua/banyan
private boolean queueExists(String queueName) throws IOException {
boolean result = true;
try {
channel.queueDeclarePassive(queueName);
} catch (IOException e) {
result = false;
if (!channel.isOpen()) {
super.init();
}
}
return result;
}
代码示例来源:origin: yanghua/banyan
public boolean exists(String queueName) throws IOException {
super.init();
boolean result = true;
try {
this.channel.queueDeclarePassive(queueName);
} catch (IOException e) {
result = false;
}
super.close();
return result;
}
代码示例来源:origin: littlersmall/rabbitmq-access
public int getMessageCount(final String queue) throws IOException {
Connection connection = connectionFactory.createConnection();
final Channel channel = connection.createChannel(false);
final AMQP.Queue.DeclareOk declareOk = channel.queueDeclarePassive(queue);
return declareOk.getMessageCount();
}
}
代码示例来源:origin: io.zipkin.zipkin2/zipkin-collector-rabbitmq
private void declareQueueIfMissing(Connection connection) throws IOException, TimeoutException {
Channel channel = connection.createChannel();
try {
// check if queue already exists
channel.queueDeclarePassive(builder.queue);
channel.close();
} catch (IOException maybeQueueDoesNotExist) {
if (maybeQueueDoesNotExist.getCause() != null && maybeQueueDoesNotExist.getCause().getMessage().contains("NOT_FOUND")) {
channel = connection.createChannel();
channel.queueDeclare(builder.queue, true, false, false, null);
channel.close();
} else {
throw maybeQueueDoesNotExist;
}
}
}
}
代码示例来源:origin: awin/rabbiteasy
/**
* Checks if all preconditions are fulfilled on the broker to
* successfully register a consumer there. One important precondition
* is the existence of the queue the consumer shall consume from.
*
* @param consumerHolders The consumer holders
* @throws IOException if the precondition check fails
*/
protected void checkPreconditions(List<ConsumerHolder> consumerHolders) throws IOException {
Channel channel = createChannel();
for (ConsumerHolder consumerHolder : consumerHolders) {
String queue = consumerHolder.getConfiguration().getQueueName();
try {
channel.queueDeclarePassive(queue);
LOGGER.debug("Queue {} found on broker", queue);
} catch (IOException e) {
LOGGER.error("Queue {} not found on broker", queue);
throw e;
}
}
channel.close();
}
代码示例来源:origin: eclipse/ditto
private void ensureQueuesExist(final Channel channel) {
final Collection<String> missingQueues = new ArrayList<>();
getSourcesOrEmptySet().forEach(consumer ->
consumer.getAddresses().forEach(address -> {
try {
channel.queueDeclarePassive(address);
} catch (final IOException e) {
missingQueues.add(address);
log.warning("The queue <{}> does not exist.", address);
}
})
);
if (!missingQueues.isEmpty()) {
log.warning("Stopping RMQ client actor for connection <{}> as queues to connect to are missing: <{}>",
connectionId(), missingQueues);
throw ConnectionFailedException.newBuilder(connectionId())
.description("The queues " + missingQueues + " to connect to are missing.")
.build();
}
}
代码示例来源:origin: org.eclipse.ditto/ditto-services-connectivity-messaging
private void ensureQueuesExist(final Channel channel) {
final Collection<String> missingQueues = new ArrayList<>();
getSourcesOrEmptySet().forEach(consumer ->
consumer.getAddresses().forEach(address -> {
try {
channel.queueDeclarePassive(address);
} catch (final IOException e) {
missingQueues.add(address);
log.warning("The queue <{}> does not exist.", address);
}
})
);
if (!missingQueues.isEmpty()) {
log.warning("Stopping RMQ client actor for connection <{}> as queues to connect to are missing: <{}>",
connectionId(), missingQueues);
throw ConnectionFailedException.newBuilder(connectionId())
.description("The queues " + missingQueues + " to connect to are missing.")
.build();
}
}
代码示例来源:origin: spring-projects/spring-amqp
static void declareTestQueue(RabbitTemplate template, final String routingKey) {
// declare and bind queue
template.execute(channel -> {
Queue.DeclareOk res = channel.queueDeclarePassive(TestConstants.QUEUE_NAME);
String queueName = res.getQueue();
System .out .println("Queue Name = " + queueName);
channel.queueBind(queueName, TestConstants.EXCHANGE_NAME, routingKey);
return queueName;
});
}
代码示例来源:origin: org.apache.camel/camel-rabbitmq
private void declareAndBindQueue(final Channel channel, final String queue, final String exchange, final String routingKey, final Map<String, Object> queueArgs,
final Map<String, Object> bindingArgs)
throws IOException {
if (endpoint.isPassive()) {
channel.queueDeclarePassive(queue);
} else {
channel.queueDeclare(queue, endpoint.isDurable(), endpoint.isExclusive(), endpoint.isAutoDelete(), queueArgs);
}
if (shouldBindQueue()) {
channel.queueBind(queue, exchange, emptyIfNull(routingKey), bindingArgs);
}
}
代码示例来源:origin: spring-projects/spring-amqp
/**
* Verify that a queue exists using the native Rabbit API to bypass all the connection and
* channel caching and callbacks in Spring AMQP.
*
* @param queue The queue to verify
* @return True if the queue exists
*/
private boolean queueExists(final Queue queue) throws Exception {
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.setHost("localhost");
connectionFactory.setPort(BrokerTestUtils.getPort());
Connection connection = connectionFactory.newConnection();
Channel channel = connection.createChannel();
try {
DeclareOk result = channel.queueDeclarePassive(queue.getName());
return result != null;
}
catch (IOException e) {
return e.getCause().getMessage().contains("RESOURCE_LOCKED");
}
finally {
connection.close();
}
}
代码示例来源:origin: spring-projects/spring-amqp
@Test
public void test(ConnectionFactory connectionFactory) throws Exception {
Connection conn = connectionFactory.newConnection();
Channel channel = conn.createChannel();
DeclareOk declareOk = channel.queueDeclarePassive("rabbitAvailableTests.queue");
assertEquals(0, declareOk.getConsumerCount());
channel.close();
conn.close();
}
代码示例来源:origin: spring-projects/spring-amqp
@Nullable
private SimpleConsumer consume(String queue, Connection connection) {
Channel channel = null;
SimpleConsumer consumer = null;
try {
channel = connection.createChannel(isChannelTransacted());
channel.basicQos(getPrefetchCount());
consumer = new SimpleConsumer(connection, channel, queue);
channel.queueDeclarePassive(queue);
consumer.consumerTag = channel.basicConsume(queue, getAcknowledgeMode().isAutoAck(),
(getConsumerTagStrategy() != null
? getConsumerTagStrategy().createConsumerTag(queue) : ""), // NOSONAR never null
isNoLocal(), isExclusive(), getConsumerArguments(), consumer);
}
catch (AmqpApplicationContextClosedException e) {
throw new AmqpConnectException(e);
}
catch (Exception e) {
RabbitUtils.closeChannel(channel);
RabbitUtils.closeConnection(connection);
consumer = handleConsumeException(queue, consumer, e);
}
return consumer;
}
代码示例来源:origin: spring-projects/spring-amqp
@Test
public void test(ConnectionFactory cf) throws Exception {
assertSame(cf, this.connectionFactory);
Connection conn = this.connectionFactory.newConnection();
Channel channel = conn.createChannel();
DeclareOk declareOk = channel.queueDeclarePassive("rabbitAvailableTests.queue");
assertEquals(0, declareOk.getConsumerCount());
channel.close();
conn.close();
}
内容来源于网络,如有侵权,请联系作者删除!