public AmqpOutboundEndpoint(AmqpTemplate amqpTemplate) { Assert.notNull(amqpTemplate, "amqpTemplate must not be null"); this.amqpTemplate = amqpTemplate; if (amqpTemplate instanceof RabbitTemplate) { setConnectionFactory(((RabbitTemplate) amqpTemplate).getConnectionFactory()); } }
@Override protected void onInit() { AmqpTemplate amqpTemplate = getAmqpTemplate(); if (this.queue == null) { if (getAdmin() == null && amqpTemplate instanceof RabbitTemplate) { ConnectionFactory connectionFactory = ((RabbitTemplate) amqpTemplate).getConnectionFactory(); setAdmin(new RabbitAdmin(connectionFactory)); setConnectionFactory(connectionFactory); } Assert.notNull(getAdmin(), "If no queueName is configured explicitly, an AmqpAdmin instance must be provided, " + "or the AmqpTemplate must be a RabbitTemplate since the Queue needs to be declared."); this.queue = new Queue(this.channelName); } super.onInit(); }
@After public void tearDown() { this.brokerRunning.removeTestQueues(); ((CachingConnectionFactory) this.rabbitTemplate.getConnectionFactory()).destroy(); }
@Test public void testInt3430FailForNotLazyConnect() { RabbitTemplate amqpTemplate = spy(new RabbitTemplate()); ConnectionFactory connectionFactory = mock(ConnectionFactory.class); RuntimeException toBeThrown = new RuntimeException("Test Connection Exception"); doThrow(toBeThrown).when(connectionFactory).createConnection(); when(amqpTemplate.getConnectionFactory()).thenReturn(connectionFactory); AmqpOutboundEndpoint handler = new AmqpOutboundEndpoint(amqpTemplate); Log logger = spy(TestUtils.getPropertyValue(handler, "logger", Log.class)); new DirectFieldAccessor(handler).setPropertyValue("logger", logger); doNothing().when(logger).error("Failed to eagerly establish the connection.", toBeThrown); ApplicationContext context = mock(ApplicationContext.class); handler.setApplicationContext(context); handler.setBeanFactory(context); handler.afterPropertiesSet(); handler.start(); handler.stop(); verify(logger, never()).error(anyString(), any(RuntimeException.class)); handler.setLazyConnect(false); handler.start(); verify(logger).error("Failed to eagerly establish the connection.", toBeThrown); handler.stop(); }
/** * @return a reference to the underlying connection factory in the * {@link RabbitTemplate}. */ public ConnectionFactory getConnectionFactory() { return this.template.getConnectionFactory(); }
/** * @return a reference to the underlying connection factory in the * {@link RabbitTemplate}. */ public ConnectionFactory getConnectionFactory() { return this.template.getConnectionFactory(); }
@Override @Nullable public <T> T execute(ChannelCallback<T> action) { return execute(action, getConnectionFactory()); }
@Override @Nullable public <T> T execute(ChannelCallback<T> action) { return execute(action, getConnectionFactory()); }
public AmqpOutboundEndpoint(AmqpTemplate amqpTemplate) { Assert.notNull(amqpTemplate, "amqpTemplate must not be null"); this.amqpTemplate = amqpTemplate; if (amqpTemplate instanceof RabbitTemplate) { setConnectionFactory(((RabbitTemplate) amqpTemplate).getConnectionFactory()); } }
/** * Construct an instance using the provided arguments. "Direct replyTo" is used for * replies. * @param template a {@link RabbitTemplate} * @since 2.0 */ public AsyncRabbitTemplate(RabbitTemplate template) { Assert.notNull(template, "'template' cannot be null"); this.template = template; this.container = null; this.replyAddress = null; this.directReplyToContainer = new DirectReplyToMessageListenerContainer(this.template.getConnectionFactory()); this.directReplyToContainer.setMessageListener(this); }
/** * Check whether the given Channel is locally transacted, that is, whether its transaction is managed by this * template's Channel handling and not by an external transaction coordinator. * @param channel the Channel to check * @return whether the given Channel is locally transacted * @see ConnectionFactoryUtils#isChannelTransactional * @see #isChannelTransacted */ protected boolean isChannelLocallyTransacted(Channel channel) { return isChannelTransacted() && !ConnectionFactoryUtils.isChannelTransactional(channel, getConnectionFactory()); }
/** * Check whether the given Channel is locally transacted, that is, whether its transaction is managed by this * template's Channel handling and not by an external transaction coordinator. * @param channel the Channel to check * @return whether the given Channel is locally transacted * @see ConnectionFactoryUtils#isChannelTransactional * @see #isChannelTransacted */ protected boolean isChannelLocallyTransacted(Channel channel) { return isChannelTransacted() && !ConnectionFactoryUtils.isChannelTransactional(channel, getConnectionFactory()); }
private void doTest(MessageCount level, Concurrency concurrency, TransactionMode transactionMode) throws Exception { RabbitTemplate template = createTemplate(concurrency.value); this.doTest(level, concurrency, transactionMode, template, template.getConnectionFactory()); }
@After public void clear() throws Exception { // Wait for broker communication to finish before trying to stop container Thread.sleep(300L); logger.debug("Shutting down at end of test"); if (container != null) { container.shutdown(); } ((DisposableBean) template.getConnectionFactory()).destroy(); this.brokerIsRunning.removeTestQueues(); }
@After public void clear() throws Exception { // Wait for broker communication to finish before trying to stop container Thread.sleep(300L); logger.debug("Shutting down at end of test"); if (container != null) { container.shutdown(); } this.brokerIsRunning.removeTestQueues(); ((DisposableBean) template.getConnectionFactory()).destroy(); }
@After public void clear() throws Exception { logger.debug("Shutting down at end of test"); if (container != null) { container.shutdown(); } ((DisposableBean) template.getConnectionFactory()).destroy(); this.brokerIsRunning.removeTestQueues(); this.executorService.shutdown(); }
@After public void clear() throws Exception { // Wait for broker communication to finish before trying to stop container logger.debug("Shutting down at end of test"); if (container != null) { container.shutdown(); } ((DisposableBean) template.getConnectionFactory()).destroy(); this.brokerIsRunning.removeTestQueues(); }
@After public void cleanup() throws Exception { this.template.stop(); ((DisposableBean) this.template.getConnectionFactory()).destroy(); this.brokerIsRunning.removeTestQueues(); }
private SimpleMessageListenerContainer createContainer(Object listener) { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(template.getConnectionFactory()); container.setMessageListener(new MessageListenerAdapter(listener)); container.setQueueNames(queue.getName()); container.setTxSize(txSize); container.setPrefetchCount(txSize); container.setConcurrentConsumers(concurrentConsumers); container.setChannelTransacted(transactional); container.setAcknowledgeMode(AcknowledgeMode.AUTO); container.afterPropertiesSet(); container.start(); return container; }
private SimpleMessageListenerContainer createContainer(Object listener) { SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(template.getConnectionFactory()); container.setMessageListener(new MessageListenerAdapter(listener)); container.setQueueNames(queue.getName()); container.setTxSize(txSize); container.setPrefetchCount(txSize); container.setConcurrentConsumers(concurrentConsumers); container.setChannelTransacted(transactional); container.setAcknowledgeMode(AcknowledgeMode.MANUAL); container.afterPropertiesSet(); container.start(); return container; }