how can microservices can communicate with each other in vertx

513 views
Skip to first unread message

Lilly

unread,
Sep 20, 2018, 5:06:11 PM9/20/18
to vert.x
Hi All,

We have a project. And planning to go for splitting the bunch of services as separate services.

As these services should be able to communicate with each other.  How to achieve this in vertx.

any suggestion will be appreciated... 

Thanks in advance !!!

MUNGAI NJOROGE

unread,
Sep 20, 2018, 5:19:51 PM9/20/18
to ve...@googlegroups.com
Hello,

Vertx uses a cluster manager to manage nodes in the network. I would recommend Hazelcast for cluster communication.
Ones the nodes form a cluster, they communicate through a distributed event bus. 

Regards. 

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/5b31c696-0afb-4106-a367-3d5dacb3a62d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Blake

unread,
Sep 20, 2018, 5:34:53 PM9/20/18
to vert.x
Hi, again, Lilly,

As Mingai said, you can use vertx's event bus to do this once clustering is setup (choose a manager like Hazelcast or Ignite. There's a list in the docs.). You may want to check out https://vertx.io/docs/vertx-service-proxy/java/ which leverages the EB, but helps you create a nicer API for it, rather than just using a JsonObject as your message.
There are more pieces you can use here too: https://vertx.io/docs/#services

Lilly

unread,
Sep 21, 2018, 1:38:47 PM9/21/18
to vert.x
Thanks Blake and Mungai

@Blake The link you have shared for Service Proxies. If services need to be on same servers. 

If I am not wrong we need to create cluster if services need to deployed on different VMs and use service proxies for them to communicate.

Blake

unread,
Sep 21, 2018, 3:24:56 PM9/21/18
to vert.x
Lilly,

I think you were asking a question there? The services do not need to be on the same server/vm. The Service Proxy is basically just a wrapper around the event bus to make calls nicer for you.

And you are correct that services need to be clustered if you want to use the eventbus (/service proxies) to communicate with them.

Lilly

unread,
Sep 23, 2018, 2:03:58 AM9/23/18
to vert.x
Again appreciate your reply Blake

I have one ServiceOne having method which is registered using ServiceBinder and is deployed on one VM

Now I need to access ServiceOne from ServiceTwo which is deployed on different VM. How to achieve this ?

Blake

unread,
Sep 23, 2018, 3:41:25 PM9/23/18
to vert.x
You need to set the verticles to cluster up. See the docs on clustering. https://vertx.io/docs/vertx-core/java/#_cluster_managers , https://vertx.io/docs/#clustering Clustering can get a little tricky depending on your network setup. So choose a cluster manager and then check the cluster managers docs if you're having problems connecting them up (the actual docs for hazelcast or w/e you chose). Once your verticles are clustered then you can simply call the service and the proxy will take care of the rest.

Lilly

unread,
Sep 23, 2018, 5:18:24 PM9/23/18
to vert.x
I got the point of creating cluster. Without proxy two services can communicate via sending message over event bus and reply back.

My question is when services are deployed of different VMs. To call methods of a particular service, we need .classfile or jar or some api related to that particular service right ?

Let suppose I have 

interface MyService {

   public void callMyService();

}

class MyServiceImpl implements MyService{

   public void callMyService(){
         /// some implementation
   }
}


public class MainVerticle extends AbstractVerticle{
       @Override
public void start() throws Exception {
         // code registering service here
     }
}


Now if I want to call callMyService() from some other service which is deployed on some other VM. How to achieve that ?

Service should has .class file or jar or should have endpoint ? 

My bad but I didn't get much help on this from documentation.

Blake

unread,
Sep 23, 2018, 6:50:40 PM9/23/18
to vert.x
Ahh, sorry had misunderstood your question.

The service proxy generates a class that you can include and use: https://vertx.io/docs/vertx-service-proxy/java/#_proxy_creation

Lilly

unread,
Sep 23, 2018, 11:03:48 PM9/23/18
to vert.x
I think I already went through this example.

And from the example I got the idea that services had dependencies on each other in order to call any method of each other.

Please correct me if I am wrong. 

That means if I have two services : ServiceOne and ServiceTwo

If ServiceOne wants to call methods of ServieTwo. ServiceOne should include jar of ServiceTwo. And than can call methods of ServiceTwo using Service Proxy. ServiceTwo can do all business logic and send result back to ServiceOne. 

Alexander Lehmann

unread,
Sep 24, 2018, 5:56:31 AM9/24/18
to vert.x
I believe the services do not have to have the dependencies of each other, so ServiceOne will call the ServiceTwo via eventbus (something like JSON rpc call) and not require any jars from ServiceTwo.
ServiceOne will only have the service proxy jar which hides the actual call and implements the interface of ServiceTwo.

Blake

unread,
Sep 24, 2018, 8:01:17 AM9/24/18
to vert.x
The service-provider does not have a dependency on the service-consumer, but the service-consumer does have a dependency on the service-provider - the example shows this. The service-provider does not need to know about the service-consumer, because it is simply using the EventBus to respond to the query. So if you have the services in different projects you'll have to figure out a way to provide the jar to the consumer - you can provide locally via .m2 or can publish the jar to your company's personal maven repo.

Lilly

unread,
Sep 24, 2018, 1:14:06 PM9/24/18
to vert.x
@Alexander 

"ServiceOne will only have the service proxy jar which hides the actual call and implements the interface of ServiceTwo".
If this is the case than how we can get object for ServiceOne in order to call it's method from ServiceTwo.


@Blake
You mean to say there is need to include provider jar of Provider in the Consumer project. And if I call provoder's method from Consumer. It actually call the provider's method which is deployed in some other server.

I think I am confused here. If possible can you explain it with some example?


On Thursday, September 20, 2018 at 2:06:11 PM UTC-7, Lilly wrote:

Blake

unread,
Sep 24, 2018, 4:24:00 PM9/24/18
to vert.x
Lilly,

Yes. You include the generated jar. The docs don't really mention including the JAR in separate projects, but I figure they assume this is obvious as you would have no other way to compile your code in a type-safe language by calling the service otherwise. The docs explain the rest pretty well. If you annotate your interface with @ProxyGen a proxy service will be generated: https://vertx.io/docs/vertx-service-proxy/java/#_proxy_creation . The example I linked earlier has a working example of this. Read the maven POMs as well to see how it includes the dependencies (it includes the provider in the consumer, but not vise versa).
Message has been deleted

伪音

unread,
May 21, 2020, 9:04:37 PM5/21/20
to vert.x
Reply all
Reply to author
Forward
0 new messages