Java Code Examples for org.springframework.amqp.rabbit.connection.CachingConnectionFactory

The following are top voted examples for showing how to use org.springframework.amqp.rabbit.connection.CachingConnectionFactory. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: https-github.com-g0t4-jenkins2-course-spring-boot   File: RabbitAutoConfigurationTests.java   View source code 6 votes vote down vote up
@Test
public void testDefaultRabbitConfiguration() {
	load(TestConfiguration.class);
	RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
	RabbitMessagingTemplate messagingTemplate = this.context
			.getBean(RabbitMessagingTemplate.class);
	CachingConnectionFactory connectionFactory = this.context
			.getBean(CachingConnectionFactory.class);
	DirectFieldAccessor dfa = new DirectFieldAccessor(connectionFactory);
	RabbitAdmin amqpAdmin = this.context.getBean(RabbitAdmin.class);
	assertThat(rabbitTemplate.getConnectionFactory()).isEqualTo(connectionFactory);
	assertThat(getMandatory(rabbitTemplate)).isFalse();
	assertThat(messagingTemplate.getRabbitTemplate()).isEqualTo(rabbitTemplate);
	assertThat(amqpAdmin).isNotNull();
	assertThat(connectionFactory.getHost()).isEqualTo("localhost");
	assertThat(dfa.getPropertyValue("publisherConfirms")).isEqualTo(false);
	assertThat(dfa.getPropertyValue("publisherReturns")).isEqualTo(false);
	assertThat(this.context.containsBean("rabbitListenerContainerFactory"))
			.as("Listener container factory should be created by default").isTrue();
}
 
Example 2
Project: https-github.com-g0t4-jenkins2-course-spring-boot   File: RabbitAutoConfigurationTests.java   View source code 6 votes vote down vote up
@Test
public void testConnectionFactoryWithOverrides() {
	load(TestConfiguration.class, "spring.rabbitmq.host:remote-server",
			"spring.rabbitmq.port:9000", "spring.rabbitmq.username:alice",
			"spring.rabbitmq.password:secret", "spring.rabbitmq.virtual_host:/vhost",
			"spring.rabbitmq.connection-timeout:123");
	CachingConnectionFactory connectionFactory = this.context
			.getBean(CachingConnectionFactory.class);
	assertThat(connectionFactory.getHost()).isEqualTo("remote-server");
	assertThat(connectionFactory.getPort()).isEqualTo(9000);
	assertThat(connectionFactory.getVirtualHost()).isEqualTo("/vhost");
	DirectFieldAccessor dfa = new DirectFieldAccessor(connectionFactory);
	com.rabbitmq.client.ConnectionFactory rcf = (com.rabbitmq.client.ConnectionFactory) dfa
			.getPropertyValue("rabbitConnectionFactory");
	assertThat(rcf.getConnectionTimeout()).isEqualTo(123);
	assertThat((Address[]) dfa.getPropertyValue("addresses")).hasSize(1);

}
 
Example 3
Project: spring-cloud-stream-binder-rabbit   File: RabbitServiceAutoConfiguration.java   View source code 6 votes vote down vote up
/**
 * Creates a {@link ConnectionFactory} using the singleton service connector.
 * @param cloud {@link Cloud} instance to be used for accessing services.
 * @param connectorConfigObjectProvider the {@link ObjectProvider} for the
 * {@link RabbitConnectionFactoryConfig}.
 * @return the {@link ConnectionFactory} used by the binder.
 */
@Bean
@Primary
ConnectionFactory rabbitConnectionFactory(Cloud cloud,
		ObjectProvider<RabbitConnectionFactoryConfig> connectorConfigObjectProvider,
		ConfigurableApplicationContext applicationContext,
		RabbitProperties rabbitProperties) throws Exception {

	ConnectionFactory connectionFactory = cloud.getSingletonServiceConnector(ConnectionFactory.class,
			connectorConfigObjectProvider.getIfUnique());

	configureCachingConnectionFactory((CachingConnectionFactory) connectionFactory,
			applicationContext, rabbitProperties);

	return connectionFactory;
}
 
Example 4
Project: spring-cloud-stream-binder-rabbit   File: RabbitMessageChannelBinder.java   View source code 6 votes vote down vote up
private void checkConnectionFactoryIsErrorCapable() {
	if (!(this.connectionFactory instanceof CachingConnectionFactory)) {
		logger.warn("Unknown connection factory type, cannot determine error capabilities: "
				+ this.connectionFactory.getClass());
	}
	else {
		CachingConnectionFactory ccf = (CachingConnectionFactory) this.connectionFactory;
		if (!ccf.isPublisherConfirms() && !ccf.isPublisherReturns()) {
			logger.warn("Producer error channel is enabled, but the connection factory is not configured for "
					+ "returns or confirms; the error channel will receive no messages");
		}
		else if (!ccf.isPublisherConfirms()) {
			logger.info("Producer error channel is enabled, but the connection factory is only configured to "
					+ "handle returned messages; negative acks will not be reported");
		}
		else if (!ccf.isPublisherReturns()) {
			logger.info("Producer error channel is enabled, but the connection factory is only configured to "
					+ "handle negatively acked messages; returned messages will not be reported");
		}
	}
}
 
Example 5
Project: resthooks   File: AmqpConfig.java   View source code 6 votes vote down vote up
@Bean
ConnectionFactory getAmqpConnectionFactory() {
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host, port);
    LOGGER.info("Creating AMQP connection factory on host {}:{}", host, port);
    if (!username.isEmpty()) {
        connectionFactory.setUsername(username);
        LOGGER.info("Logging to AMQP with username ", username);
    } else {
        LOGGER.warn("Logging to AMQP with NO username");
    }
    if (!password.isEmpty()) {
        connectionFactory.setPassword(password);
        LOGGER.info("Logging to AMQP with password {}", password.replaceAll(".", "*"));
    } else {
        LOGGER.warn("Logging to AMQP with NO password");
    }
    return connectionFactory;
}
 
Example 6
Project: spring-boot-concourse   File: RabbitAutoConfigurationTests.java   View source code 6 votes vote down vote up
@Test
public void testDefaultRabbitConfiguration() {
	load(TestConfiguration.class);
	RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
	RabbitMessagingTemplate messagingTemplate = this.context
			.getBean(RabbitMessagingTemplate.class);
	CachingConnectionFactory connectionFactory = this.context
			.getBean(CachingConnectionFactory.class);
	DirectFieldAccessor dfa = new DirectFieldAccessor(connectionFactory);
	RabbitAdmin amqpAdmin = this.context.getBean(RabbitAdmin.class);
	assertThat(rabbitTemplate.getConnectionFactory()).isEqualTo(connectionFactory);
	assertThat(getMandatory(rabbitTemplate)).isFalse();
	assertThat(messagingTemplate.getRabbitTemplate()).isEqualTo(rabbitTemplate);
	assertThat(amqpAdmin).isNotNull();
	assertThat(connectionFactory.getHost()).isEqualTo("localhost");
	assertThat(dfa.getPropertyValue("publisherConfirms")).isEqualTo(false);
	assertThat(dfa.getPropertyValue("publisherReturns")).isEqualTo(false);
	assertThat(this.context.containsBean("rabbitListenerContainerFactory"))
			.as("Listener container factory should be created by default").isTrue();
}
 
Example 7
Project: spring-boot-concourse   File: RabbitAutoConfigurationTests.java   View source code 6 votes vote down vote up
@Test
public void testConnectionFactoryWithOverrides() {
	load(TestConfiguration.class, "spring.rabbitmq.host:remote-server",
			"spring.rabbitmq.port:9000", "spring.rabbitmq.username:alice",
			"spring.rabbitmq.password:secret", "spring.rabbitmq.virtual_host:/vhost",
			"spring.rabbitmq.connection-timeout:123");
	CachingConnectionFactory connectionFactory = this.context
			.getBean(CachingConnectionFactory.class);
	assertThat(connectionFactory.getHost()).isEqualTo("remote-server");
	assertThat(connectionFactory.getPort()).isEqualTo(9000);
	assertThat(connectionFactory.getVirtualHost()).isEqualTo("/vhost");
	DirectFieldAccessor dfa = new DirectFieldAccessor(connectionFactory);
	com.rabbitmq.client.ConnectionFactory rcf = (com.rabbitmq.client.ConnectionFactory) dfa
			.getPropertyValue("rabbitConnectionFactory");
	assertThat(rcf.getConnectionTimeout()).isEqualTo(123);
}
 
Example 8
Project: generic-vnfm   File: EMSConfiguration.java   View source code 6 votes vote down vote up
@PostConstruct
private void init() {
  log.info("Initialization of RabbitConfiguration");

  emsConnectionFactory = new CachingConnectionFactory();
  ((CachingConnectionFactory) emsConnectionFactory).setHost(brokerIp);
  ((CachingConnectionFactory) emsConnectionFactory).setPort(rabbitPort);
  ((CachingConnectionFactory) emsConnectionFactory).setUsername(emsRabbitUsername);
  ((CachingConnectionFactory) emsConnectionFactory).setPassword(emsRabbitPassword);

  rabbitAdmin = new RabbitAdmin(emsConnectionFactory);
  TopicExchange topicExchange = new TopicExchange("openbaton-exchange");
  rabbitAdmin.declareExchange(topicExchange);
  log.info("exchange declared");

  queueName_emsRegistrator = "ems." + vnfmHelper.getVnfmEndpoint() + ".register";
  rabbitAdmin.declareQueue(new Queue(queueName_emsRegistrator, durable, exclusive, autodelete));
}
 
Example 9
Project: contestparser   File: RabbitAutoConfiguration.java   View source code 6 votes vote down vote up
@Bean
public CachingConnectionFactory rabbitConnectionFactory(RabbitProperties config)
		throws Exception {
	RabbitConnectionFactoryBean factory = new RabbitConnectionFactoryBean();
	if (config.getHost() != null) {
		factory.setHost(config.getHost());
		factory.setPort(config.getPort());
	}
	if (config.getUsername() != null) {
		factory.setUsername(config.getUsername());
	}
	if (config.getPassword() != null) {
		factory.setPassword(config.getPassword());
	}
	if (config.getVirtualHost() != null) {
		factory.setVirtualHost(config.getVirtualHost());
	}
	if (config.getRequestedHeartbeat() != null) {
		factory.setRequestedHeartbeat(config.getRequestedHeartbeat());
	}
	RabbitProperties.Ssl ssl = config.getSsl();
	if (ssl.isEnabled()) {
		factory.setUseSSL(true);
		factory.setKeyStore(ssl.getKeyStore());
		factory.setKeyStorePassphrase(ssl.getKeyStorePassword());
		factory.setTrustStore(ssl.getTrustStore());
		factory.setTrustStorePassphrase(ssl.getTrustStorePassword());
	}
	factory.afterPropertiesSet();
	CachingConnectionFactory connectionFactory = new CachingConnectionFactory(
			factory.getObject());
	connectionFactory.setAddresses(config.getAddresses());
	return connectionFactory;
}
 
Example 10
Project: contestparser   File: RabbitAutoConfigurationTests.java   View source code 6 votes vote down vote up
@Test
public void testDefaultRabbitConfiguration() {
	load(TestConfiguration.class);
	RabbitTemplate rabbitTemplate = this.context.getBean(RabbitTemplate.class);
	RabbitMessagingTemplate messagingTemplate = this.context
			.getBean(RabbitMessagingTemplate.class);
	CachingConnectionFactory connectionFactory = this.context
			.getBean(CachingConnectionFactory.class);
	RabbitAdmin amqpAdmin = this.context.getBean(RabbitAdmin.class);
	assertEquals(connectionFactory, rabbitTemplate.getConnectionFactory());
	assertEquals(rabbitTemplate, messagingTemplate.getRabbitTemplate());
	assertNotNull(amqpAdmin);
	assertEquals("localhost", connectionFactory.getHost());
	assertTrue("Listener container factory should be created by default",
			this.context.containsBean("rabbitListenerContainerFactory"));
}
 
Example 11
Project: hawkbit   File: AmqpTestConfiguration.java   View source code 6 votes vote down vote up
@Bean
ConnectionFactory rabbitConnectionFactory(final RabbitMqSetupService rabbitmqSetupService) {
    final CachingConnectionFactory factory = new CachingConnectionFactory();
    factory.setHost(rabbitmqSetupService.getHostname());
    factory.setPort(5672);
    factory.setUsername(rabbitmqSetupService.getUsername());
    factory.setPassword(rabbitmqSetupService.getPassword());
    try {
        factory.setVirtualHost(rabbitmqSetupService.createVirtualHost());
        // All exception are catched. The BrokerRunning decide if the
        // test should break or not
    } catch (@SuppressWarnings("squid:S2221") final Exception e) {
        Throwables.propagateIfInstanceOf(e, AlivenessException.class);
        LOG.error("Cannot create virtual host {}", e.getMessage());
    }
    return factory;
}
 
Example 12
Project: cf-service-tester   File: StandaloneConfig.java   View source code 6 votes vote down vote up
@Bean
public ConnectionFactory rabbitConnectionFactory() {
	com.rabbitmq.client.ConnectionFactory cf = new com.rabbitmq.client.ConnectionFactory();
	cf.setNetworkRecoveryInterval(rabbitNetworkRecoveryInterval);
	cf.setRequestedHeartbeat(rabbitHeartbeatInterval);
	
	CachingConnectionFactory connectionFactory = new CachingConnectionFactory(cf);
	connectionFactory.setVirtualHost(rabbitVirtualHost);
	connectionFactory.setAddresses(rabbitAddresses);
	connectionFactory.setUsername(rabbitUsername);
    connectionFactory.setPassword(rabbitPassword);
    connectionFactory.setPublisherConfirms(publisherConfirms);
    connectionFactory.setConnectionTimeout(rabbitConnectionTimeout);
    connectionFactory.setChannelCheckoutTimeout(rabbitChannelCheckoutTimeout);
    connectionFactory.setCloseTimeout(rabbitCloseTimeout);
    return connectionFactory;
}
 
Example 13
Project: elpaaso-core   File: DatasourceCloudContext.java   View source code 6 votes vote down vote up
@Bean(name="rabbitMQConnectionFactory")
public ConnectionFactory rabbitConnectionFactory() {
	CloudFactory cloudFactory = new CloudFactory();
	Cloud cloud = cloudFactory.getCloud();

	AmqpServiceInfo amqpServiceInfo = (AmqpServiceInfo) cloud.getServiceInfo("activationAmqpBroker");

	String serviceID = amqpServiceInfo.getId();
	ConnectionFactory connectionFactory = cloud.getServiceConnector(serviceID, ConnectionFactory.class, null);
	try{
		LOGGER.info("Setting CachingConnectionFactory specific properties");
		((CachingConnectionFactory)connectionFactory).setChannelCacheSize(channelCacheSize);
		((CachingConnectionFactory)connectionFactory).setRequestedHeartBeat(requestedHeartbeat);
		((CachingConnectionFactory)connectionFactory).setConnectionTimeout(connectionTimeout);
	}   catch (ClassCastException cce){
		throw new TechnicalException("Cannot customize CachingConnectionFactory for rabbitConnectionFactory");
	}
	return connectionFactory;
}
 
Example 14
Project: cukes   File: RabbitMQConfiguration.java   View source code 6 votes vote down vote up
@Bean
@DependsOn("amqpBroker")
CachingConnectionFactory connectionFactory() {
    log.info("Creating connection factory for MQ broker...");
    ConnectionFactory cf = new ConnectionFactory();
    cf.setHost(hostname);
    cf.setPort(port);
    cf.setUsername(userName);
    cf.setPassword(password);
    cf.setVirtualHost(virtualHost);
    cf.setAutomaticRecoveryEnabled(false);
    if (useSSL) {
        try {
            cf.useSslProtocol();
        } catch (NoSuchAlgorithmException | KeyManagementException e) {
            //TODO don't throw raw exceptions
            throw new RuntimeException(e);
        }
    }

    log.info("Connection factory created.");
    return new CachingConnectionFactory(cf);
}
 
Example 15
Project: async-amqp-messaging   File: ReceiveController.java   View source code 6 votes vote down vote up
/**
 * Creates a new connection to an AMQP broker with the given information.
 */
private void connectToBroker()
{
  if (this.objConnection == null)
  {
    this.objConnection = new CachingConnectionFactory();
    String host = this.objResources.getConfiguration().getHost();
    String addresses = "";
    for (int port : this.objResources.getConfiguration().getPorts())
    {
      addresses = addresses + host + ":" + port + ",";
    }
    this.objConnection.setAddresses(addresses);
    this.objConnection.setUsername(this.objResources.getConfiguration().getUsername());
    this.objConnection.setPassword(this.objResources.getConfiguration().getPassword());
    this.objConnection.setChannelCacheSize(25);
  }
}
 
Example 16
Project: async-amqp-messaging   File: SendController.java   View source code 6 votes vote down vote up
/**
 * Creates a new connection to an AMQP broker with the given information.
 */
private void connectToBroker()
{
  if (this.objConnection == null)
  {
    this.objConnection = new CachingConnectionFactory();

    Configuration config = this.objResources.getConfiguration();
    String host = config.getHost();
    String addresses = "";
    for (int port : config.getPorts())
    {
      addresses = addresses + host + ":" + port + ", ";
    }
    this.objConnection.setAddresses(addresses);
    this.objConnection.setUsername(config.getUsername());
    this.objConnection.setPassword(config.getPassword());
    this.objConnection.setChannelCacheSize(25);
  }
}
 
Example 17
Project: bulbs-core   File: NotificationConfig.java   View source code 6 votes vote down vote up
@Bean
public ConnectionFactory rabbitConnectionFactory(
        @Value("${rabbitMq.connection.host}") String host,
        @Value("${rabbitMq.connection.port}") Integer port,
        @Value("${rabbitMq.connection.username:}") String username,
        @Value("${rabbitMq.connection.password:}") String password
) {
    CachingConnectionFactory connectionFactory =
        new CachingConnectionFactory(host, port);
    connectionFactory.setUsername(username);
    connectionFactory.setPassword(password);
    connectionFactory.setChannelCacheSize(1);
    List<ChannelListener> listeners = new LinkedList<>();
    listeners.add(
            (channel, transactional) -> log.info("Channel created; Number:  " + channel.getChannelNumber())
    );
    connectionFactory.setChannelListeners(listeners);
    this.connectionFactory = connectionFactory;
    return connectionFactory;
}
 
Example 18
Project: spring-cloud-connectors   File: RabbitConnectionFactoryCreator.java   View source code 6 votes vote down vote up
private CachingConnectionFactory createSpringConnectionFactory(AmqpServiceInfo serviceInfo,
															   ServiceConnectorConfig serviceConnectorConfiguration,
															   com.rabbitmq.client.ConnectionFactory connectionFactory) {
	CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(connectionFactory);

	if (serviceInfo.getUris() != null) {
		cachingConnectionFactory.setAddresses(getAddresses(serviceInfo));
	}

	if (serviceConnectorConfiguration != null) {
		Integer channelCacheSize = ((RabbitConnectionFactoryConfig) serviceConnectorConfiguration).getChannelCacheSize();
		if (channelCacheSize != null) {
			cachingConnectionFactory.setChannelCacheSize(channelCacheSize);
		}
	}

	return cachingConnectionFactory;
}
 
Example 19
Project: cloud-pos-router   File: RabbitConfiguration.java   View source code 6 votes vote down vote up
@Bean
public ConnectionFactory connectionFactory() {
    final URI ampqUrl;
    try {
        ampqUrl = new URI(getEnvOrThrow("CLOUDAMQP_URL"));
    } catch (URISyntaxException e) {
        throw new RuntimeException(e);
    }

    final CachingConnectionFactory factory = new CachingConnectionFactory();
    factory.setUsername(ampqUrl.getUserInfo().split(":")[0]);
    factory.setPassword(ampqUrl.getUserInfo().split(":")[1]);
    factory.setHost(ampqUrl.getHost());
    factory.setPort(ampqUrl.getPort());
    factory.setVirtualHost(ampqUrl.getPath().substring(1));
    factory.setPublisherReturns(true);

    return factory;
}
 
Example 20
Project: microservices-spring   File: RabbitMqConfiguration.java   View source code 5 votes vote down vote up
@Bean
ConnectionFactory connectionFactory() {
    CachingConnectionFactory factory = new CachingConnectionFactory();
    factory.setUsername(username);
    factory.setPassword(password);
    factory.setAddresses(addresses);
    return factory;
}
 
Example 21
Project: microservices-spring   File: RabbitMqConfiguration.java   View source code 5 votes vote down vote up
@Bean
ConnectionFactory connectionFactory() {
    CachingConnectionFactory factory = new CachingConnectionFactory();
    factory.setUsername(username);
    factory.setPassword(password);
    factory.setAddresses(addresses);
    return factory;
}
 
Example 22
Project: microservices-spring   File: RabbitMqConfiguration.java   View source code 5 votes vote down vote up
@Bean
ConnectionFactory connectionFactory() {
    CachingConnectionFactory factory = new CachingConnectionFactory();
    factory.setUsername(username);
    factory.setPassword(password);
    factory.setAddresses(addresses);
    return factory;
}
 
Example 23
Project: springboot-sample   File: RabbitmqConfiguration.java   View source code 5 votes vote down vote up
@Bean(name = "connectionFactory")
public ConnectionFactory getConnectionFactory() {
    CachingConnectionFactory factory = new CachingConnectionFactory();
    factory.setHost(rabbitMQProperties.getHost());
    factory.setUsername(rabbitMQProperties.getUsername());
    factory.setPassword(rabbitMQProperties.getPassword());
    factory.setVirtualHost(rabbitMQProperties.getVhost());
    factory.setPublisherConfirms(true);
    factory.setPublisherReturns(true);
    return factory;
}
 
Example 24
Project: java-learn   File: SpringClientDemo.java   View source code 5 votes vote down vote up
public CachingConnectionFactory cachingConnectionFactory(){
    com.rabbitmq.client.ConnectionFactory connectionFactory = new com.rabbitmq.client.ConnectionFactory();
    connectionFactory.setHost("dev");
    connectionFactory.setPort(5672);
    connectionFactory.setUsername("admin");
    connectionFactory.setPassword("admin");
    connectionFactory.setVirtualHost("/learn");
    return new CachingConnectionFactory(connectionFactory);
}
 
Example 25
Project: dataProvider   File: SingletonConnectionFactory.java   View source code 5 votes vote down vote up
public static CachingConnectionFactory getConnection(String host, String username, String password){

        if (connectionFactory == null) {
            createFactory(host, username, password);
        }

        return connectionFactory;
    }
 
Example 26
Project: spring-integration-dsl-samle   File: AbstractNotificationFlowConfiguration.java   View source code 5 votes vote down vote up
@Bean
public CachingConnectionFactory rabbitMQConnection(){
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setHost("127.0.0.1");
    connectionFactory.setPort(5672);
    connectionFactory.setUsername("guest");
    connectionFactory.setPassword("guest");
    return connectionFactory;
}
 
Example 27
Project: spring-integration-dsl-samle   File: AbstractOrderFlowConfiguration.java   View source code 5 votes vote down vote up
@Bean
public CachingConnectionFactory rabbitMQConnection(){
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setHost("127.0.0.1");
    connectionFactory.setPort(5672);
    connectionFactory.setUsername("guest");
    connectionFactory.setPassword("guest");
    return connectionFactory;
}
 
Example 28
Project: spring-integration-dsl-samle   File: AbstractWarehouseFlowConfiguration.java   View source code 5 votes vote down vote up
@Bean
public CachingConnectionFactory rabbitMQConnection(){
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    connectionFactory.setHost("127.0.0.1");
    connectionFactory.setPort(5672);
    connectionFactory.setUsername("guest");
    connectionFactory.setPassword("guest");
    return connectionFactory;
}
 
Example 29
Project: acme-solution   File: CommandBusConfigurer.java   View source code 5 votes vote down vote up
@Bean
public ConnectionFactory commandBusConnectionFactory() {

    log.info("Creating command bus connection on hostname: {" + this.hostname + "}");

    final CachingConnectionFactory connectionFactory = new CachingConnectionFactory(this.hostname, this.port);
    connectionFactory.setUsername(this.username);
    connectionFactory.setPassword(this.password);

    return connectionFactory;
}
 
Example 30
Project: acme-solution   File: EventBusConfigurer.java   View source code 5 votes vote down vote up
@Bean
public ConnectionFactory eventBusConnectionFactory() {

    log.info("Creating query event bus connection on hostname: {" + this.hostname + "}");

    final CachingConnectionFactory connectionFactory = new CachingConnectionFactory(this.hostname, this.port);
    connectionFactory.setUsername(this.username);
    connectionFactory.setPassword(this.password);

    return connectionFactory;
}
 
Example 31
Project: acme-solution   File: RabbitConfigurer.java   View source code 5 votes vote down vote up
@Bean
public ConnectionFactory getConnectionFactory() {

    log.info("Creating rabbit connection for command bus, publishing, on host: {" + this.hostname + "}");

    final CachingConnectionFactory connectionFactory = new CachingConnectionFactory(this.hostname, this.port);
    connectionFactory.setUsername(this.username);
    connectionFactory.setPassword(this.password);

    return connectionFactory;
}
 
Example 32
Project: acme-solution   File: EventBusConfigurer.java   View source code 5 votes vote down vote up
@Bean
@Primary
public ConnectionFactory eventBusConnectionFactory() {

    log.info("Creating event bus connection on hostname: {" + this.hostname + "}");

    final CachingConnectionFactory connectionFactory = new CachingConnectionFactory(this.hostname, this.port);
    connectionFactory.setUsername(this.username);
    connectionFactory.setPassword(this.password);

    return connectionFactory;
}
 
Example 33
Project: spring-rabbitmq-actuator   File: QueueCheckTest.java   View source code 5 votes vote down vote up
@Test
public void testConstructor()
{
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);

    Queue queue = new Queue("test");
    queue.setAdminsThatShouldDeclare(rabbitAdmin);

    QueueCheck queueCheck = new QueueCheck(queue, 10000, 2);
    Assert.assertEquals(10000, queueCheck.getMaxMessageCount());
    Assert.assertEquals(2, queueCheck.getMinConsumerCount());
    Assert.assertNotNull(queueCheck.getQueue());
    Assert.assertNotNull(queueCheck.getRabbitAdmin());
}
 
Example 34
Project: spring-rabbitmq-actuator   File: QueueUtil.java   View source code 5 votes vote down vote up
public static Queue generateQueue(String name)
{
    CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
    RabbitAdmin rabbitAdmin = new RabbitAdmin(connectionFactory);

    Queue queue = new Queue(name);
    queue.setAdminsThatShouldDeclare(rabbitAdmin);

    return queue;
}
 
Example 35
Project: Microservices-Building-Scalable-Software   File: TurbineApp.java   View source code 5 votes vote down vote up
@Bean
public ConnectionFactory connectionFactory() {
    //LOG.info("Creating RabbitMQHost ConnectionFactory for host: {}", rabbitMQHost);

    CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(rabbitMQHost);
    return cachingConnectionFactory;
}
 
Example 36
Project: Microservices-Building-Scalable-Software   File: TurbineApp.java   View source code 5 votes vote down vote up
@Bean
public ConnectionFactory connectionFactory() {
    //LOG.info("Creating RabbitMQHost ConnectionFactory for host: {}", rabbitMQHost);

    CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(rabbitMQHost);
    return cachingConnectionFactory;
}
 
Example 37
Project: Microservices-Building-Scalable-Software   File: TurbineApp.java   View source code 5 votes vote down vote up
@Bean
public ConnectionFactory connectionFactory() {
    //LOG.info("Creating RabbitMQHost ConnectionFactory for host: {}", rabbitMQHost);

    CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(rabbitMQHost);
    return cachingConnectionFactory;
}
 
Example 38
Project: https-github.com-g0t4-jenkins2-course-spring-boot   File: RabbitAutoConfigurationTests.java   View source code 5 votes vote down vote up
@Test
public void testConnectionFactoryEmptyVirtualHost() {
	load(TestConfiguration.class, "spring.rabbitmq.virtual_host:");
	CachingConnectionFactory connectionFactory = this.context
			.getBean(CachingConnectionFactory.class);
	assertThat(connectionFactory.getVirtualHost()).isEqualTo("/");
}
 
Example 39
Project: https-github.com-g0t4-jenkins2-course-spring-boot   File: RabbitAutoConfigurationTests.java   View source code 5 votes vote down vote up
@Test
public void testConnectionFactoryVirtualHostNoLeadingSlash() {
	load(TestConfiguration.class, "spring.rabbitmq.virtual_host:foo");
	CachingConnectionFactory connectionFactory = this.context
			.getBean(CachingConnectionFactory.class);
	assertThat(connectionFactory.getVirtualHost()).isEqualTo("foo");
}
 
Example 40
Project: https-github.com-g0t4-jenkins2-course-spring-boot   File: RabbitAutoConfigurationTests.java   View source code 5 votes vote down vote up
@Test
public void testConnectionFactoryVirtualHostMultiLeadingSlashes() {
	load(TestConfiguration.class, "spring.rabbitmq.virtual_host:///foo");
	CachingConnectionFactory connectionFactory = this.context
			.getBean(CachingConnectionFactory.class);
	assertThat(connectionFactory.getVirtualHost()).isEqualTo("///foo");
}