@Override protected void connectCallback(final Channel channel) throws IOException { super.connectCallback(channel); if (getConfig().isDeclaring()) { channel.queueDeclare(getName(), getConfig().isDurable(), getConfig().isExclusive(), getConfig().isAutoDelete(), null); } channel.basicConsume(getName(), false, getConsumer()); } }
protected void channelDisconnect() { final Channel channel = channelHolder.getAndSet(null); disconnectCallback(channel); AmqpUtils.closeQuietly(channel); final Connection connection = connectionHolder.getAndSet(null); AmqpUtils.closeQuietly(connection); }
@Override protected void publish(final PublisherData publisherData) throws IOException { final Channel channel = channelConnect(); // A queue is a routing key on the default exchange... channel.basicPublish("", getName(), publisherData.getProperties(), publisherData.getData()); } }
@Override protected void connectCallback(@Nonnull final Channel channel) throws IOException { super.connectCallback(channel); if (getConfig().isDeclaring()) { channel.exchangeDeclare(getName(), getConfig().getExchangeType(), getConfig().isDurable(), getConfig().isAutoDelete(), null); } final String queueName = channel.queueDeclare().getQueue(); channel.queueBind(queueName, getName(), routingKey); channel.basicConsume(queueName, false, getConsumer()); } }
@Override protected boolean process() throws IOException, InterruptedException { // Only connect the transmitter if lazy-connect is false. if (!getConfig().isLazyTransmitterConnect()) { channelConnect(); } final T data = messageQueue.poll(tickTimeout.getPeriod(), tickTimeout.getUnit()); if (data != null) { final PublisherData publisherData = publisherCallback.publish(data); if (publisherData != null) { publish(publisherData); return getChannel().isOpen() && publisherData.isHealthy(); } } return true; }
@Override protected void connectCallback(@Nonnull final Channel channel) throws IOException { if (getConfig().isDeclaring()) { channel.exchangeDeclare(getName(), getConfig().getExchangeType(), getConfig().isDurable(), getConfig().isAutoDelete(), null); } }
@Override protected void connectCallback(@Nonnull final Channel channel) throws IOException { if (getConfig().isDeclaring()) { channel.queueDeclare(getName(), getConfig().isDurable(), getConfig().isExclusive(), getConfig().isAutoDelete(), null); } }
@Override protected void publish(final PublisherData publisherData) throws IOException { final Channel channel = channelConnect(); // An exchange has its own name and the default routing key... channel.basicPublish(getName(), routingKey, publisherData.getProperties(), publisherData.getData()); } }
private void backoff(final Throwable t) throws InterruptedException { final long backoffTime = amqpConfig.getBackoffDelay().getMillis() * backoff; LOG.warnDebug(t, "Could not connect to Broker, sleeping for %d ms...", backoffTime); Thread.sleep(backoffTime); if (backoff != 1 << amqpConfig.getMaxBackoffFactor()) { backoff <<= 1; } channelDisconnect(); }
protected AbstractConsumer(@Nonnull final ConnectionFactory connectionFactory, @Nonnull final AmqpConfig amqpConfig, @Nonnull final String name, @Nonnull final ConsumerCallback consumerCallback) { super(connectionFactory, amqpConfig, name); this.consumerCallback = consumerCallback; this.tickTimeout = getConfig().getTickTimeout().getMillis(); }
@After public void tearDown() throws Exception { getProvider().shutdown(); }
@After public void tearDown() throws Exception { getProvider().shutdown(); }
@After public void tearDown() throws Exception { getProvider().shutdown(); }
/** * Creates a new {@link ExchangePublisher}. The Publisher accepts arbitrary objects and uses the Jackson object mapper to convert them into * JSON and sends them as a text message. */ public <T> ExchangePublisher<T> createExchangeJsonPublisher(final String name) { Preconditions.checkState(connectionFactory != null, "connection factory was never injected!"); return new ExchangePublisher<T>(connectionFactory, amqpConfig, name, jsonPublisherCallback); }
/** * Creates a new {@link QueuePublisher}. The callback is called to convert an object that is sent into the QueuePublisher * into an AMQP byte array.. */ public <T> QueuePublisher<T> createQueuePublisher(final String name, final PublisherCallback<T> messageCallback) { Preconditions.checkState(connectionFactory != null, "connection factory was never injected!"); return new QueuePublisher<T>(connectionFactory, amqpConfig, name, messageCallback); }
/** * Creates a new {@link ExchangeConsumer}. For every message received (or when the timeout waiting for messages is hit), the callback * is invoked with the message received. */ public ExchangeConsumer createExchangeListener(final String name, final ConsumerCallback messageCallback) { Preconditions.checkState(connectionFactory != null, "connection factory was never injected!"); return new ExchangeConsumer(connectionFactory, amqpConfig, name, messageCallback); }
/** * Creates a new {@link QueueConsumer}. For every message received (or when the timeout waiting for messages is hit), the callback * is invoked with the message received. */ public QueueConsumer createQueueListener(final String name, final ConsumerCallback messageCallback) { Preconditions.checkState(connectionFactory != null, "connection factory was never injected!"); return new QueueConsumer(connectionFactory, amqpConfig, name, messageCallback); } }
public ExchangePublisher(@Nonnull final ConnectionFactory connectionFactory, @Nonnull final AmqpConfig amqpConfig, @Nonnull final String name, @Nonnull final PublisherCallback<? super T> publisherCallback) { super(connectionFactory, amqpConfig, name, publisherCallback); this.routingKey = amqpConfig.getRoutingKey(); }
/** * Creates a new {@link ExchangePublisher}. The Publisher accepts strings and sends them as a text message. */ public ExchangePublisher<String> createExchangeTextPublisher(final String name) { Preconditions.checkState(connectionFactory != null, "connection factory was never injected!"); return new ExchangePublisher<String>(connectionFactory, amqpConfig, name, stringPublisherCallback); }
/** * Creates a new {@link QueuePublisher}. The Publisher accepts arbitrary objects and uses the Jackson object mapper to convert them into * JSON and sends them as a text message. */ public <T> QueuePublisher<T> createQueueJsonPublisher(final String name) { Preconditions.checkState(connectionFactory != null, "connection factory was never injected!"); return new QueuePublisher<T>(connectionFactory, amqpConfig, name, jsonPublisherCallback); }