spring-cloud-stream icon indicating copy to clipboard operation
spring-cloud-stream copied to clipboard

Default binding properties are ignored when binding-specific properties and multi-binder environment are both defined

Open Nephery opened this issue 3 years ago • 2 comments

Describe the issue Default binding properties are ignored when both spring.cloud.stream.<binder>.bindings.<binding>.consumer/producer.<property> and spring.cloud.stream.binders.<custom-binder-name>.environment.<property> are both defined.

To Reproduce Steps to reproduce the behavior:

  1. Use the sensor-average-reactive-rabbit sample and upgrade spring-boot-starter-parent to 2.6.2 and spring-cloud.version to 2021.0.0.
  2. In this sample's application.yml, add:
spring:
  cloud:
    stream:
      binders:
        local-rabbit:
          type: rabbit
          environment:
            host: localhost

      rabbit:
        bindings:
          receive-in-0:
            consumer:
              durableSubscription: false
        default:
          consumer:
            anonymousGroupPrefix: 'test.'

management: # Not required to reproduce this issue, but I included it here to enable the actuator endpoint for the next steps
  endpoints:
    web:
      exposure:
        include: bindings
  1. Run the application.
  2. See in actuator that the receive-in-0 binding has anonymousGroupPrefix set to anonymous., ignoring the default consumer binding property that we had defined at spring.cloud.stream.rabbit.default.consumer.anonymousGroupPrefix.

Now if you were to re-run the application with either spring.cloud.stream.binders.local-rabbit.environment or spring.cloud.stream.rabbit.bindings commented out from application.yml, notice in actuator that the receive-in-0 binding has anonymousGroupPrefix set to test. as expected.

Version of the framework spring-boot-starter-parent: 2.6.2 spring-cloud-dependencies: 2021.0.0

Expected behavior

Default binding properties should be applied when spring.cloud.stream.<binder>.bindings.<binding>.consumer/producer.<property> and spring.cloud.stream.binders.<custom-binder-name>.environment.<property> are both defined in application.yml.

In step 4 of the issue reproduction, we should have seen anonymousGroupPrefix set to test., not anonymous..

Additional context This issue was originally found using the Solace PubSub+ binder. See https://github.com/SolaceProducts/solace-spring-cloud/issues/29.

Nephery avatar Jan 05 '22 19:01 Nephery

Having a similar issue over here.

My situation: 2 bindings b1 and b2. A seperate binder is configured for b2 because it uses a different RabbitMQ virtual host. I define a default property to always use quorum queues instead of the standard 'classic' queues.

spring.rabbitmq.virtual-host=vh1

spring.cloud.stream.rabbit.default.consumer.quorum.enabled=true

spring.cloud.stream.binders.rabbitmq-vh2.type=rabbit
spring.cloud.stream.binders.rabbitmq-vh2.default-candidate=false
spring.cloud.stream.binders.rabbitmq-vh2.inherit-environment=true
spring.cloud.stream.binders.rabbitmq-vh2.environment.spring.rabbitmq.virtual-host=vh2

spring.cloud.stream.bindings.b1-in-0.destination=b1
spring.cloud.stream.bindings.b1-in-0.group=my-app
spring.cloud.stream.bindings.b2-in-0.binder=rabbitmq-vh2
spring.cloud.stream.bindings.b2-in-0.destination=b2
spring.cloud.stream.bindings.b2-in-0.group=my-app

Expected result:

RabbitMQ virtualhost vh1:

  • Quorum queue: - b1.my-app

RabbitMQ virtualhost vh2:

  • Quorum queue: - b2.my-app

Actual result:

RabbitMQ virtualhost vh1:

  • Quorum queue: - b1.my-app

RabbitMQ virtualhost vh2:

  • Classic queue: - b2.my-app

The 'b2-in-0 ' binding did not use the default configuration for quorum queues.

rvervaek avatar Jul 15 '22 13:07 rvervaek

Chatting to @mrc0113 and yes indeed it was an issue and It was also filed under https://github.com/spring-cloud/spring-cloud-stream/issues/2283 and fixed yesterday and back-ported to 3.2.x So please, double check it with the latest

I'll keep this open for now

olegz avatar Oct 05 '22 15:10 olegz

I retested it with:

  • Spring Boot 2.7.5
  • Spring Cloud 2021.0.4
  • spring-cloud-stream dependency built with the 3.2.x branch (HEAD is d37e785a7d5f454f3058aeb0ffdd71ca96ebea37)

But the bug is still happening.

Nephery avatar Oct 26 '22 16:10 Nephery

@Nephery Unfortunately I can't reproduce it. In fact the behavior I see is that it works Here is my app (modeled after the example from one of the comments from @rvervaek ) Basically I see that in both binder instances quorum is set to be enabled.

Please let me know what I may be missing as I can not reproduce the behavior you are describing

APPLICATION:

@SpringBootApplication
public class SpringCloudStream2610Application {

    public static void main(String[] args) {
        SpringApplication.run(SpringCloudStream2610Application.class, args);
    }

    @Bean
    public Function<Message<?>, Message<?>> hire() {
    	return v -> {
    		System.out.println("RECEIVED: " + v);
    		return v;
    	};
    }
}

CONFIGURATION:

spring.cloud.function.definition=hire

spring.cloud.stream.binders.input-binder.type=rabbit
spring.cloud.stream.binders.output-binder.type=rabbit

spring.cloud.stream.bindings.hire-in-0.binder=input-binder
spring.cloud.stream.bindings.hire-in-0.destination=input
spring.cloud.stream.bindings.hire-in-0.group=input-group

spring.cloud.stream.bindings.hire-out-0.binder=output-binder
spring.cloud.stream.bindings.hire-out-0.destination=output
spring.cloud.stream.bindings.hire-out-0.group=output-group

spring.cloud.stream.rabbit.default.consumer.quorum.enabled=true

spring.cloud.stream.binders.input-binder.environment.spring.rabbitmq.host=localhost
spring.cloud.stream.binders.output-binder.environment.spring.rabbitmq.host=localhost

RELEVANT POM SEGMENT:

<properties>
		<java.version>1.8</java.version>
		<spring-cloud.version>2021.0.5</spring-cloud.version>
	</properties>
	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-stream</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>	
	</dependencies>
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>${spring-cloud.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

olegz avatar Jan 12 '23 11:01 olegz

@Nephery 3.2.7-SNAPSHOT is available, please give it a shot to ensure that it works for you

olegz avatar Jan 12 '23 18:01 olegz

I retested it. Looks like its working now. Thanks @olegz

Nephery avatar Jan 13 '23 17:01 Nephery