@Override protected void onInit() { super.onInit(); if (!this.initialized && this.rabbitTemplate != null) { if (this.connectionFactory != null) { this.connectionFactory.addConnectionListener(this); } } this.initialized = true; }
@Override public void addConnectionListener(ConnectionListener listener) { this.defaultConnectionFactory.addConnectionListener(listener); }
@Override public void addConnectionListener(ConnectionListener listener) { this.defaultConnectionFactory.addConnectionListener(listener); }
@Override public void addConnectionListener(ConnectionListener listener) { for (ConnectionFactory connectionFactory : this.targetConnectionFactories.values()) { connectionFactory.addConnectionListener(listener); } if (this.defaultTargetConnectionFactory != null) { this.defaultTargetConnectionFactory.addConnectionListener(listener); } this.connectionListeners.add(listener); }
/** * Adds the given {@link ConnectionFactory} and associates it with the given lookup key. * @param key the lookup key. * @param connectionFactory the {@link ConnectionFactory}. */ protected void addTargetConnectionFactory(Object key, ConnectionFactory connectionFactory) { this.targetConnectionFactories.put(key, connectionFactory); for (ConnectionListener listener : this.connectionListeners) { connectionFactory.addConnectionListener(listener); } }
@Override public void addConnectionListener(ConnectionListener listener) { for (ConnectionFactory connectionFactory : this.targetConnectionFactories.values()) { connectionFactory.addConnectionListener(listener); } if (this.defaultTargetConnectionFactory != null) { this.defaultTargetConnectionFactory.addConnectionListener(listener); } this.connectionListeners.add(listener); }
/** * Adds the given {@link ConnectionFactory} and associates it with the given lookup key. * @param key the lookup key. * @param connectionFactory the {@link ConnectionFactory}. */ protected void addTargetConnectionFactory(Object key, ConnectionFactory connectionFactory) { this.targetConnectionFactories.put(key, connectionFactory); for (ConnectionListener listener : this.connectionListeners) { connectionFactory.addConnectionListener(listener); } }
@Override protected void onInit() { super.onInit(); if (!this.initialized && this.rabbitTemplate != null) { if (this.connectionFactory != null) { this.connectionFactory.addConnectionListener(this); } } this.initialized = true; }
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; }
@Override public Consumer createConsumer(Processor processor) throws Exception { if(this.exchangeName == null) throw new IllegalStateException("Cannot have null exchange name"); //Aha! We're a consumer, so the second argument was a queue name. This is a fanout exchange. if(this.tempQueueOrKey != null) { this.queueName = this.tempQueueOrKey; this.tempQueueOrKey = null; if(this.exchangeType == null) this.exchangeType = "fanout"; } if(this.queueName == null) throw new IllegalStateException("Cannot have null queue name for "+getEndpointUri()); SpringAMQPConsumer consumer = new SpringAMQPConsumer(this, processor); if(getAmqpTemplate() != null) ((RabbitTemplate) getAmqpTemplate()).getConnectionFactory().addConnectionListener(consumer); return consumer; }
@Bean public ConnectionFactory cf1() throws IOException { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); when(connectionFactory.createConnection()).thenReturn(conn1); when(conn1.createChannel(false)).thenReturn(channel1); when(channel1.queueDeclare("foo", true, false, false, new HashMap<>())) .thenReturn(new AMQImpl.Queue.DeclareOk("foo", 0, 0)); doAnswer(invocation -> { listener1 = invocation.getArgument(0); return null; }).when(connectionFactory).addConnectionListener(any(ConnectionListener.class)); return connectionFactory; }
@Override public Consumer createConsumer(Processor processor) throws Exception { if(this.exchangeName == null) throw new IllegalStateException("Cannot have null exchange name"); //Aha! We're a consumer, so the second argument was a queue name. This is a fanout exchange. if(this.tempQueueOrKey != null) { this.queueName = this.tempQueueOrKey; this.tempQueueOrKey = null; if(this.exchangeType == null) this.exchangeType = "fanout"; } if(this.queueName == null) throw new IllegalStateException("Cannot have null queue name for "+getEndpointUri()); SpringAMQPConsumer consumer = new SpringAMQPConsumer(this, processor); if(getAmqpTemplate() != null) ((RabbitTemplate) getAmqpTemplate()).getConnectionFactory().addConnectionListener(consumer); return consumer; }
@Bean public ConnectionFactory cf2() throws IOException { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); when(connectionFactory.createConnection()).thenReturn(conn2); when(conn2.createChannel(false)).thenReturn(channel2); when(channel2.queueDeclare("foo", true, false, false, null)) .thenReturn(new AMQImpl.Queue.DeclareOk("foo", 0, 0)); doAnswer(invocation -> { listener2 = invocation.getArgument(0); return null; }).when(connectionFactory).addConnectionListener(any(ConnectionListener.class)); return connectionFactory; }
@Test public void testAddTargetConnectionFactoryAddsExistingConnectionListenersToConnectionFactory() { AbstractRoutingConnectionFactory routingFactory = new AbstractRoutingConnectionFactory() { @Override protected Object determineCurrentLookupKey() { return null; } }; routingFactory.addConnectionListener(Mockito.mock(ConnectionListener.class)); routingFactory.addConnectionListener(Mockito.mock(ConnectionListener.class)); ConnectionFactory targetConnectionFactory = Mockito.mock(ConnectionFactory.class); routingFactory.addTargetConnectionFactory("1", targetConnectionFactory); verify(targetConnectionFactory, times(2)).addConnectionListener(any(ConnectionListener.class)); }
this.connectionFactory.addConnectionListener(connection -> {
listener.set((ConnectionListener) invocation.getArguments()[0]); return null; }).when(cf).addConnectionListener(any(ConnectionListener.class)); RabbitAdmin admin = new RabbitAdmin(cf); GenericApplicationContext context = new GenericApplicationContext();
listener.set(invocation.getArgument(0)); return null; }).when(cf).addConnectionListener(any(ConnectionListener.class)); RabbitAdmin admin = new RabbitAdmin(cf); GenericApplicationContext context = new GenericApplicationContext();
listener.set(invocation.getArgument(0)); return null; }).when(cf).addConnectionListener(any(ConnectionListener.class)); RabbitAdmin admin = new RabbitAdmin(cf); GenericApplicationContext context = new GenericApplicationContext();
listener.set(invocation.getArgument(0)); return null; }).when(cf).addConnectionListener(any(ConnectionListener.class)); RabbitAdmin admin = new RabbitAdmin(cf); RabbitAdmin other = new RabbitAdmin(cf);