Skip to content

Instantly share code, notes, and snippets.

public interface MyBeerOutput {
String OUTPUT = "output";
@Output(Source.OUTPUT)
MessageChannel output();
}
public interface MyBeerOutput {
String OUTPUT = "output";
@Output(MyBeerOutput.OUTPUT)
MessageChannel output();
}
#mykafka or myrabbit?
spring.cloud.stream.defaultBinder = myrabbit
#Target Stream for beers channel
spring.cloud.stream.bindings.output.destination = beers-channel
#RabbitMQ Settings:
spring.cloud.stream.binders.myrabbit.type = rabbit
spring.cloud.stream.binders.myrabbit.environment.spring.rabbitmq.addresses = localhost:5672
#mykafka or myrabbit?
spring.cloud.stream.defaultBinder = mykafka
#Target Stream for beers channel
spring.cloud.stream.bindings.output.destination = beers-channel
#Kafka Settings:
spring.cloud.stream.binders.mykafka.type = kafka
spring.cloud.stream.binders.mykafka.environment.spring.cloud.stream.kafka.binder.brokers = localhost:9092
spring.cloud.stream.binders.mykafka.environment.spring.cloud.stream.kafka.binder.zkNodes = localhost:2181
@SpringBootApplication
@EnableBinding(Source.class)
public class BeerClientApplication {
public static void main(String[] args) {
SpringApplication.run(BeerClientApplication.class, args);
}
}
@Component
@Slf4j
class BeerHandler {
@Autowired
BeerRepository repo;
@StreamListener(target=Sink.INPUT)
public void handleBeerMessage (String message) {
log.info("Received beer: {}", message);
#myrabbit or mykafka?
spring.cloud.stream.defaultBinder = mykafka
spring.cloud.stream.bindings.input.destination=beers-channel
spring.cloud.stream.bindings.input.group = beers-group
#Kafka Settings:
spring.cloud.stream.binders.mykafka.type = kafka
spring.cloud.stream.binders.mykafka.environment.spring.cloud.stream.kafka.binder.brokers = localhost:9092
spring.cloud.stream.binders.mykafka.environment.spring.cloud.stream.kafka.binder.zkNodes = localhost:2181
#myrabbit or mykafka?
spring.cloud.stream.defaultBinder = myrabbit
spring.cloud.stream.bindings.input.destination=beers-channel
spring.cloud.stream.bindings.input.group = beers-group
#RabbitMQ Settings:
spring.cloud.stream.binders.myrabbit.type = rabbit
spring.cloud.stream.binders.myrabbit.environment.spring.rabbitmq.addresses = localhost:5672
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.Output;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.Output;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;