Spring Cloud Stream: Cannot connect to 2 rabbitmq clusters without allowOverride - spring-boot

I have a spring boot application (let's call it example-service) with the following configuration to connect to 2 different rabbitmq clusters.
spring:
cloud:
stream:
defaultBinder: rabbitA
binders:
rabbitA:
inheritEnvironment: false
defaultCandidate: false
type: rabbit
environment:
spring:
rabbitmq:
addresses: rabbitmq-a:5672
username: user-a
password: password-a
rabbitB:
inheritEnvironment: false
defaultCandidate: false
type: rabbit
environment:
spring:
rabbitmq:
addresses: rabbitmq-b:5672
username: user-b
password: password-b
bindings:
dataFromA:
destination: exchange-1
group: queue-1
binder: rabbitA
dataFromB:
destination: exchange-2
group: queue-2
binder: rabbitB
That itself works fine, it connects to both clusters. The problem is that this service is deployed in an environment where there is a spring config server with the following files:
application.yml
spring.rabbitmq:
addresses: rabbitmq-a:5672
username: user-a
password: password-a
Then that seems to override the configuration set for each binder, located under the "environment" property. So I needed to add this extra config.
example-service.yml
spring.cloud:
config:
overrideSystemProperties: false
allowOverride: true
overrideNone: false
Now the example-service connects to both rabbitmq clusters again. But I have observed certain side effects, mainly not being able to override other properties in the config server example-service.yml anymore, which is a real need for me. So I have discarded using allowOverride and its related properties.
The question is... is it possible to make it work without using allowOverride, while keeping the spring.rabbitmq.addresses/username/password in the remote config server application.yml?
Thank you very much in advance.
Kind regards.

Which version are you using? I just tested it with 3.0.6 and it works fine:
spring:
cloud:
stream:
binders:
rabbitA:
type: rabbit
inherit-environment: false
environment:
spring:
rabbitmq:
virtual-host: A
rabbitB:
type: rabbit
inherit-environment: false
environment:
spring:
rabbitmq:
virtual-host: B
bindings:
input1:
binder: rabbitA
destination: input1
group: foo
input2:
binder: rabbitB
destination: input2
group: bar
rabbitmq:
virtual-host: /
Probably not related, but your group indentation is wrong.

Related

How to use application.propeties in spring cloud config client application?

How to use application.yml in spring cloud config client application?
spring:
application:
name: app-cli
profiles:
active: DEV
config:
import: "configserver:"
cloud:
config:
name: ${spring.application.name}
uri: http://192.168.0.12:8888
username: thirumal
password: thirumal
request-read-timeout: 200
request-connect-timeout: 100
fail-fast: true
The client app is configure with all the required properties, still it's not connecting to config-server.
The lib implementation 'org.springframework.cloud:spring-cloud-starter-config'

Multiple Configuration for Spring Cloud Load Balancer

Similar question asked in Spring Cloud Load Balancer multiple configurations.
I want to use health-check and same-instance-preference configurations for spring cloud load balancer at the same time. Unable to give mutiple configurations.
I am using SimpleDiscoveryClient for listing out the instances. Additionally, if both these configurations are clubbed, can it be a replacement for sticky session loadbalancer rule?
Posting my yml here:
spring:
application:
name: sample
cloud:
discovery:
client:
health-indicator:
enabled: false
simple:
instances:
test-service:
- uri: http://localhost:8082
- uri: http://localhost:8081
loadbalancer:
# configurations: health-check
configurations: same-instance-preference
sticky-session:
add-service-instance-cookie: true
cache:
enabled: false
health-check:
path:
default: /actuator/health
interval: 10000
gateway:
routes:
- id: test_routing
path: /user/*
uri: lb://test-service
predicates:
- Method=GET,POST
- Path=/user/**
server:
port: 45000

SCDF kubernetes custom source is writing data to "ouput" channel

I have custom source application which reads data from external kafka server and pass the information to next processor in the stream. In local everything works perfect. I have created docker image of the code and when i deploy stream in kubernetes env, i do see topic with the name stream.source-app got created but messages produced by source are actually going to "output" topic. I dont see this issue in local env.
application.yaml
spring:
cloud:
stream:
bindings:
Workitemconnector_subscribe:
destination: Workitemconnector
contentType: application/json
group: SCDFMessagingSourceTestTool1
consumer:
partitioned: true
concurrency: 1
headerMode: embeddedHeaders
output:
# destination: dataOut
binder: kafka2
binders:
kafka1:
type: kafka
environment:
spring:
cloud:
stream:
kafka:
binder:
brokers: xx.xxx.xx.xxx:9092
zkNodes: xx.xxx.xx.xxx:2181
kafka2:
type: kafka
environment:
spring:
cloud:
stream:
kafka:
binder:
brokers: server1:9092
zkNodes: server1:2181
spring.cloud.stream.defaultBinder: kafka1
In local without defining any parameters during stream deployment, i notice source is consuming message from xxxx server and producing data to server1 and to the topic name "stream.sourceapp" but in kubernetes env it is acting strange. It is always sending data to "output" topic even though "stream.sourceapp" topic exists

Spring cloud composite bootstrap.yml

Is there any way how to "build" bootstrap.yml from multiple yaml files?
Here is my scenario, I have a bunch of micro-services and every service had the same bootstrap.yml properties expect spring.application.name.
I would like to split my bootstrap.yml into two files, base-bootstrap.yml which contains config service configuration like URI, password ... etc and then bootstrap.yml which could contain spring.application.name or whatever else.
base-bootstrap.yml file could be externalized in some dependency jar and should be used like default, bootstrap.yml should override any value. Here is some sample:
base-boostrap.yml
spring:
cloud:
config:
label: develop
uri: http://config
password: ${CONFIG_SERVICE_PASSWORD:password}
fail-fast: true
---
spring:
profiles: production
cloud:
config:
label: master
password: ${CONFIG_SERVICE_PASSWORD}
---
spring:
profiles: development
cloud:
config:
uri: http://localhost:8888
bootstrap.yml
spring:
application.name: sample-service
cloud:
config:
label: release/1.0.1
---
spring:
profiles: production
cloud:
config:
label: 1.1.0
Could anyone please guide me how to do it?

How to monitor amqp/rabbitMQ connection with Spring?

We have two different AMQP servers (RabbitMQ) and configured one binder for each one.
What is the best way to check the connection status to each of the amqp servers?
One way seems to be to use a AmqpTemplate with CachingConnectionFactory, where one can configure the host. But is there an easier way?
I also tried to go through List<HealthIndicator>. But it contains only one RabbitHealthIndicator when there should be two.
Our config:
spring:
cloud:
stream:
binders:
binder1:
type: rabbit
environment:
spring:
rabbitmq:
host: localhost
port: 5672
password: guest
username: guest
binder2:
type: rabbit
environment:
spring:
rabbitmq:
host: localhost
port: 56721
password: guest
username: guest
So, you have to declare one more RabbitHealthIndicator for the RabbitTemplate on the second ConnectionFactory.
http://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html#_writing_custom_healthindicators

Resources