public AmqpInboundGateway(AbstractMessageListenerContainer listenerContainer) { this(listenerContainer, new RabbitTemplate(listenerContainer.getConnectionFactory()), false); }
/** * Construct an instance with the supplied name, container and template; default header * mappers will be used if the message is mapped. * @param channelName the channel name. * @param container the container. * @param amqpTemplate the template. * @param isPubSub true for a pub/sub channel. * @param outboundMapper the outbound mapper. * @param inboundMapper the inbound mapper. * @see #setExtractPayload(boolean) * @since 4.3 */ protected AbstractSubscribableAmqpChannel(String channelName, AbstractMessageListenerContainer container, AmqpTemplate amqpTemplate, boolean isPubSub, AmqpHeaderMapper outboundMapper, AmqpHeaderMapper inboundMapper) { super(amqpTemplate, outboundMapper, inboundMapper); Assert.notNull(container, "container must not be null"); Assert.hasText(channelName, "channel name must not be empty"); this.channelName = channelName; this.container = container; this.isPubSub = isPubSub; setConnectionFactory(container.getConnectionFactory()); setAdmin(new RabbitAdmin(getConnectionFactory())); }
public AmqpInboundGateway(AbstractMessageListenerContainer listenerContainer) { this(listenerContainer, new RabbitTemplate(listenerContainer.getConnectionFactory()), false); }
private BrokerEventListener(AbstractMessageListenerContainer container, boolean ownContainer, String... eventKeys) { Assert.notNull(container, "listener container cannot be null"); Assert.isTrue(!ObjectUtils.isEmpty(eventKeys), "At least one event key is required"); this.container = container; this.container.setQueues(this.eventQueue); this.container.setMessageListener(this); this.eventKeys = Arrays.copyOf(eventKeys, eventKeys.length); this.container.getConnectionFactory().addConnectionListener(this); this.admin = new RabbitAdmin(this.container.getConnectionFactory()); this.ownContainer = ownContainer; }
private BrokerEventListener(AbstractMessageListenerContainer container, boolean ownContainer, String... eventKeys) { Assert.notNull(container, "listener container cannot be null"); Assert.isTrue(!ObjectUtils.isEmpty(eventKeys), "At least one event key is required"); this.container = container; this.container.setQueues(this.eventQueue); this.container.setMessageListener(this); this.eventKeys = Arrays.copyOf(eventKeys, eventKeys.length); this.container.getConnectionFactory().addConnectionListener(this); this.admin = new RabbitAdmin(this.container.getConnectionFactory()); this.ownContainer = ownContainer; }
/** * Construct an instance with the supplied name, container and template; default header * mappers will be used if the message is mapped. * @param channelName the channel name. * @param container the container. * @param amqpTemplate the template. * @param isPubSub true for a pub/sub channel. * @param outboundMapper the outbound mapper. * @param inboundMapper the inbound mapper. * @see #setExtractPayload(boolean) * @since 4.3 */ protected AbstractSubscribableAmqpChannel(String channelName, AbstractMessageListenerContainer container, AmqpTemplate amqpTemplate, boolean isPubSub, AmqpHeaderMapper outboundMapper, AmqpHeaderMapper inboundMapper) { super(amqpTemplate, outboundMapper, inboundMapper); Assert.notNull(container, "container must not be null"); Assert.hasText(channelName, "channel name must not be empty"); this.channelName = channelName; this.container = container; this.isPubSub = isPubSub; setConnectionFactory(container.getConnectionFactory()); setAdmin(new RabbitAdmin(getConnectionFactory())); }
protected void checkMismatchedQueues() { if (this.mismatchedQueuesFatal && this.amqpAdmin != null) { try { this.amqpAdmin.initialize(); } catch (AmqpConnectException e) { logger.info("Broker not available; cannot check queue declarations"); } catch (AmqpIOException e) { if (RabbitUtils.isMismatchedQueueArgs(e)) { throw new FatalListenerStartupException("Mismatched queues", e); } else { logger.info("Failed to get connection during start(): " + e); } } } else { try { Connection connection = getConnectionFactory().createConnection(); // NOSONAR if (connection != null) { connection.close(); } } catch (Exception e) { logger.info("Broker not available; cannot force queue declarations during start"); } } }
protected void checkMismatchedQueues() { if (this.mismatchedQueuesFatal && this.amqpAdmin != null) { try { this.amqpAdmin.initialize(); } catch (AmqpConnectException e) { logger.info("Broker not available; cannot check queue declarations"); } catch (AmqpIOException e) { if (RabbitUtils.isMismatchedQueueArgs(e)) { throw new FatalListenerStartupException("Mismatched queues", e); } else { logger.info("Failed to get connection during start(): " + e); } } } else { try { Connection connection = getConnectionFactory().createConnection(); // NOSONAR if (connection != null) { connection.close(); } } catch (Exception e) { logger.info("Broker not available; cannot force queue declarations during start"); } } }
private void cleanUpAfterInvoke(@Nullable RabbitResourceHolder resourceHolder, Channel channelToUse, boolean boundHere) { if (resourceHolder != null && boundHere) { // so the channel exposed (because exposeListenerChannel is false) will be closed resourceHolder.setSynchronizedWithTransaction(false); } ConnectionFactoryUtils.releaseResources(resourceHolder); // NOSONAR - null check in method if (boundHere) { // unbind if we bound TransactionSynchronizationManager.unbindResource(this.getConnectionFactory()); if (!isExposeListenerChannel() && isChannelLocallyTransacted()) { /* * commit the temporary channel we exposed; the consumer's channel * will be committed later. Note that when exposing a different channel * when there's no transaction manager, the exposed channel is committed * on each message, and not based on txSize. */ RabbitUtils.commitIfNecessary(channelToUse); } } }
private void cleanUpAfterInvoke(@Nullable RabbitResourceHolder resourceHolder, Channel channelToUse, boolean boundHere) { if (resourceHolder != null && boundHere) { // so the channel exposed (because exposeListenerChannel is false) will be closed resourceHolder.setSynchronizedWithTransaction(false); } ConnectionFactoryUtils.releaseResources(resourceHolder); // NOSONAR - null check in method if (boundHere) { // unbind if we bound TransactionSynchronizationManager.unbindResource(this.getConnectionFactory()); if (!isExposeListenerChannel() && isChannelLocallyTransacted()) { /* * commit the temporary channel we exposed; the consumer's channel * will be committed later. Note that when exposing a different channel * when there's no transaction manager, the exposed channel is committed * on each message, and not based on txSize. */ RabbitUtils.commitIfNecessary(channelToUse); } } }
RabbitResourceHolder resourceHolder = new RabbitResourceHolder(channel, false); resourceHolder.setSynchronizedWithTransaction(true); TransactionSynchronizationManager.bindResource(this.getConnectionFactory(), resourceHolder); if (bindChannel) { TransactionSynchronizationManager.unbindResource(this.getConnectionFactory());
RabbitResourceHolder resourceHolder = new RabbitResourceHolder(channel, false); resourceHolder.setSynchronizedWithTransaction(true); TransactionSynchronizationManager.bindResource(this.getConnectionFactory(), resourceHolder); if (bindChannel) { TransactionSynchronizationManager.unbindResource(this.getConnectionFactory());
!TransactionSynchronizationManager.isActualTransactionActive()) { resourceHolder.setSynchronizedWithTransaction(true); TransactionSynchronizationManager.bindResource(this.getConnectionFactory(), resourceHolder); boundHere = true; RabbitResourceHolder localResourceHolder = new RabbitResourceHolder(channelToUse, false); localResourceHolder.setSynchronizedWithTransaction(true); TransactionSynchronizationManager.bindResource(this.getConnectionFactory(), localResourceHolder); boundHere = true;
!TransactionSynchronizationManager.isActualTransactionActive()) { resourceHolder.setSynchronizedWithTransaction(true); TransactionSynchronizationManager.bindResource(this.getConnectionFactory(), resourceHolder); boundHere = true; RabbitResourceHolder localResourceHolder = new RabbitResourceHolder(channelToUse, false); localResourceHolder.setSynchronizedWithTransaction(true); TransactionSynchronizationManager.bindResource(this.getConnectionFactory(), localResourceHolder); boundHere = true;
private void assertBasicConfig(AbstractMessageListenerContainer container) { DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(container); assertSame(connectionFactory, container.getConnectionFactory()); assertSame(errorHandler, fieldAccessor.getPropertyValue("errorHandler")); assertSame(messageConverter, fieldAccessor.getPropertyValue("messageListener.messageConverter")); assertEquals(AcknowledgeMode.MANUAL, container.getAcknowledgeMode()); assertEquals(true, container.isChannelTransacted()); assertEquals(false, container.isAutoStartup()); assertEquals(99, container.getPhase()); }