org.springframework.boot.autoconfigure.amqp.RabbitProperties Java Examples

The following examples show how to use org.springframework.boot.autoconfigure.amqp.RabbitProperties. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RabbitServiceAutoConfiguration.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 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}.
 * @param applicationContext application context instance
 * @param rabbitProperties rabbit properties
 * @return the {@link ConnectionFactory} used by the binder.
 * @throws Exception if configuration of connection factory fails
 */
@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 #2
Source File: RepublishUnitTests.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 6 votes vote down vote up
@Test
public void testBadRepublishSetting() throws IOException {
	ConnectionFactory cf = mock(ConnectionFactory.class);
	Connection conn = mock(Connection.class);
	given(cf.createConnection()).willReturn(conn);
	Channel channel = mock(Channel.class);
	given(channel.isOpen()).willReturn(true);
	given(channel.exchangeDeclarePassive("DLX")).willThrow(new IOException());
	given(conn.createChannel(false)).willReturn(channel);
	RabbitProperties props = new RabbitProperties();
	RabbitMessageChannelBinder binder = new RabbitMessageChannelBinder(cf, props, null);
	RabbitConsumerProperties extension = new RabbitConsumerProperties();
	ExtendedConsumerProperties<RabbitConsumerProperties> bindingProps =
			new ExtendedConsumerProperties<RabbitConsumerProperties>(extension);
	MessageHandler handler = binder.getErrorMessageHandler(mock(ConsumerDestination.class), "foo", bindingProps);
	ErrorMessage message = new ErrorMessage(new RuntimeException("test"),
			Collections.singletonMap(IntegrationMessageHeaderAccessor.SOURCE_DATA,
					new Message("foo".getBytes(), new MessageProperties())));
	handler.handleMessage(message);
	handler.handleMessage(message);
	verify(channel, times(1)).exchangeDeclarePassive("DLX");
	verify(channel, never()).basicPublish(any(), any(), eq(false), any(), any());
}
 
Example #3
Source File: SpringAmqpStubMessages.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Autowired
public SpringAmqpStubMessages(RabbitTemplate rabbitTemplate,
		MessageListenerAccessor messageListenerAccessor,
		RabbitProperties rabbitProperties) {
	Assert.notNull(rabbitTemplate, "RabbitTemplate must be set");
	Assert.isTrue(
			mockingDetails(rabbitTemplate).isSpy()
					|| mockingDetails(rabbitTemplate).isMock(),
			"StubRunner AMQP will work only if RabbiTemplate is a spy");
	this.rabbitTemplate = rabbitTemplate;
	this.messageListenerAccessor = messageListenerAccessor;
	this.rabbitProperties = rabbitProperties;
}
 
Example #4
Source File: RabbitServiceAutoConfiguration.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 5 votes vote down vote up
static void configureCachingConnectionFactory(
		CachingConnectionFactory connectionFactory,
		ConfigurableApplicationContext applicationContext,
		RabbitProperties rabbitProperties) throws Exception {

	if (StringUtils.hasText(rabbitProperties.getAddresses())) {
		connectionFactory.setAddresses(rabbitProperties.determineAddresses());
	}

	connectionFactory.setPublisherConfirmType(rabbitProperties.getPublisherConfirmType() == null ? ConfirmType.NONE : rabbitProperties.getPublisherConfirmType());
	connectionFactory.setPublisherReturns(rabbitProperties.isPublisherReturns());
	if (rabbitProperties.getCache().getChannel().getSize() != null) {
		connectionFactory.setChannelCacheSize(
				rabbitProperties.getCache().getChannel().getSize());
	}
	if (rabbitProperties.getCache().getConnection().getMode() != null) {
		connectionFactory
				.setCacheMode(rabbitProperties.getCache().getConnection().getMode());
	}
	if (rabbitProperties.getCache().getConnection().getSize() != null) {
		connectionFactory.setConnectionCacheSize(
				rabbitProperties.getCache().getConnection().getSize());
	}
	if (rabbitProperties.getCache().getChannel().getCheckoutTimeout() != null) {
		connectionFactory.setChannelCheckoutTimeout(rabbitProperties.getCache()
				.getChannel().getCheckoutTimeout().toMillis());
	}
	connectionFactory.setApplicationContext(applicationContext);
	applicationContext.addApplicationListener(connectionFactory);
	connectionFactory.afterPropertiesSet();
}
 
Example #5
Source File: RabbitMessageChannelBinder.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 5 votes vote down vote up
public RabbitMessageChannelBinder(ConnectionFactory connectionFactory,
		RabbitProperties rabbitProperties,
		RabbitExchangeQueueProvisioner provisioningProvider,
		ListenerContainerCustomizer<AbstractMessageListenerContainer> containerCustomizer) {

	this(connectionFactory, rabbitProperties, provisioningProvider, containerCustomizer, null);
}
 
Example #6
Source File: RabbitMessageChannelBinder.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 5 votes vote down vote up
public RabbitMessageChannelBinder(ConnectionFactory connectionFactory,
		RabbitProperties rabbitProperties,
		RabbitExchangeQueueProvisioner provisioningProvider,
		ListenerContainerCustomizer<AbstractMessageListenerContainer> containerCustomizer,
		MessageSourceCustomizer<AmqpMessageSource> sourceCustomizer) {

	super(new String[0], provisioningProvider, containerCustomizer, sourceCustomizer);
	Assert.notNull(connectionFactory, "connectionFactory must not be null");
	Assert.notNull(rabbitProperties, "rabbitProperties must not be null");
	this.connectionFactory = connectionFactory;
	this.rabbitProperties = rabbitProperties;
}
 
Example #7
Source File: RabbitBinderTests.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 5 votes vote down vote up
@Override
protected RabbitTestBinder getBinder() {
	if (this.testBinder == null) {
		RabbitProperties rabbitProperties = new RabbitProperties();
		rabbitProperties.setPublisherConfirmType(ConfirmType.SIMPLE);
		rabbitProperties.setPublisherReturns(true);
		this.testBinder = new RabbitTestBinder(rabbitAvailableRule.getResource(),
				rabbitProperties);
	}
	return this.testBinder;
}
 
Example #8
Source File: RabbitMqSetupService.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
public RabbitMqSetupService(final RabbitProperties properties) {
    hostname = properties.getHost();
    username = properties.getUsername();
    if (StringUtils.isEmpty(username)) {
        username = DEFAULT_USER;
    }

    password = properties.getPassword();
    if (StringUtils.isEmpty(password)) {
        password = DEFAULT_PASSWORD;
    }

}
 
Example #9
Source File: ZipkinRabbitSenderConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Bean(ZipkinAutoConfiguration.SENDER_BEAN_NAME)
Sender rabbitSender(CachingConnectionFactory connectionFactory,
		RabbitProperties config) {
	String addresses = StringUtils.hasText(this.addresses) ? this.addresses
			: config.determineAddresses();
	return RabbitMQSender.newBuilder()
			.connectionFactory(connectionFactory.getRabbitConnectionFactory())
			.queue(this.queue).addresses(addresses).build();
}
 
Example #10
Source File: RabbitMessageChannelBinder.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 4 votes vote down vote up
public RabbitMessageChannelBinder(ConnectionFactory connectionFactory,
		RabbitProperties rabbitProperties,
		RabbitExchangeQueueProvisioner provisioningProvider) {

	this(connectionFactory, rabbitProperties, provisioningProvider, null, null);
}
 
Example #11
Source File: RabbitTestBinder.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 4 votes vote down vote up
public RabbitTestBinder(ConnectionFactory connectionFactory,
		RabbitProperties rabbitProperties) {
	this(connectionFactory, new RabbitMessageChannelBinder(connectionFactory,
			rabbitProperties, new RabbitExchangeQueueProvisioner(connectionFactory)));
}
 
Example #12
Source File: AmqpTestConfiguration.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
@Bean
RabbitMqSetupService rabbitmqSetupService(final RabbitProperties properties) {
    return new RabbitMqSetupService(properties);
}