Skip to content

Latest commit

 

History

History
77 lines (50 loc) · 2.53 KB

README.md

File metadata and controls

77 lines (50 loc) · 2.53 KB

Build Status Maven Central Codacy Badge codecov

RabbitMQ

RabbitMQ integration with scalecube services

Features:

  • Java 8, RxJava Observers
  • serialization , byte[], string , json, google protocol buffers
  • Exchange , Queue

Basic Usage

Given a micro-service located somewhere in the cluster. we wish to communicated with it via rabbit mq api gateway and json format:

 // Provision a Micro-cluster for the service provider
Microservices serviceProvider = Microservices.builder()
    // serviceProvider will join the gateway micro-cluster
    // this Micro-cluster provision GreetingService microservice instance
    .services(new GreetingServiceImpl())
    .build();



// Acquire proxy to the microservice from any member (see scalecube microservices for more info).
GreetingService service = gateway.proxy()
    .api(GreetingService.class)
    .create();  
// declare topics:
private static final Topic REQUEST_TOPIC = Topic.builder().name("TOPIC_GREETING_SERVICE_REQUESTS").build();

private static final Topic RESPONSE_TOPIC = Topic.builder().name("TOPIC_GREETING_SERVICE_RESPONSES").build();


// RabbitMQ API Gateway on rabbit localhost.
RMQ serviceQueue = RMQ.builder().json().host("localhost").build();

// listen on GreetingRequest from request topic.
serviceQueue.topic(REQUEST_TOPIC)
	.listen(GreetingRequest.class).subscribe(onNext -> {

// call the microservice onNext MQ request.	
service.greeting(onNext).whenComplete((response, ex) -> {
    try {
      serviceQueue.publish(RESPONSE_TOPIC, response);
    } catch (Exception e) {
    	//...
    }
  });
});


RMQ publisher = RMQ.builder().json().host("localhost").build();

// listen on GreetingResponse from response topic.
publisher.topic(RESPONSE_TOPIC).listen(GreetingResponse.class).subscribe(onNext -> {
  // do stuff with response from service.
});


publisher.publish(REQUEST_TOPIC, new GreetingRequest("joe"));