Spring cloud streams - vidyasekaran/current_learning GitHub Wiki
A soap based client server applications can be loosely coupled but if we use soap to integrate then A Sevice need to know B service's endpoint, then it means they loosely coupled but not logically as still they both need to know each other.
SOAP Over Http is logically coupled.
so if we have the message of generic way the client can set values and put in topic and server using soap adapter convert and use. so if data format from soap is changed we need not change client and server..So if we can create an in memory queue and have so many adapters then we can use it to integrate client/server, this way we can convert message format and go forward.
we can have many inmemory channels - where each processor reads validates and puts in next channel like way the flow can proceed...we can have a router which copies data to multiple channels... where 3 adapater (soap, json, xml) will be good right...
AMQP - we use exchange - messages will have routing key - exhange copy it to specific queue
Suppose we have 3 queues x, y, z - Message has header which has routing key where if routing key "x" the exhange will send the message to X queue. Receivers will receive message from queue.
different type of exchange - topic (1 to many), direct exchange, fan out.
Rabbitmq implements amqp, spring cloud stream allows us to create in memory channels and this channel we can bind this channel to exchange broker. internally adapter does it but all these are configuable where we can use rabiitmq, kafka etc.. Create in memory channel and bind it to broker exchange this is configurable.
Message to go out define OutputChannel - @output("helloutchannel")
@Output("hellooutchannel") MessageChannel myoutput()
For Implementatino that this "hellooutchannel" to map to which exhange ?? Define binder and config in xml...
define an interface
public interface MySource {
@Output("hellooutchannel")
MessageChannel myoutput();
@Input("helloinchannel")
SubscribableChannel myinput();
}
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</artifactId>
</dependency>
application.yml
spring: cloud: stream: bindings: hellooutchannel: destination: helloexchange group: helloq binder: rabbit1
binders:
rabbit1:
type: rabbit
environment:
spring:
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
Invoke on source object of class MySource @EnableBinding for message to be sent
@SpringBootApplication @EnableBinding(MySource.class) public class Application
@GetMapping("/greet")
public Greeting createGreeting(String message) {
Greeting greeting=new Greeting(message);
System.err.println("Sending greeting!! ");
source.myoutput().send(MessageBuilder.withPayload(greeting).build());
return greeting;