Dmitry Belkin
Dmitry Belkin

Reputation: 3

How to exchange data between instances of the same service in Consul?

I'm trying a combination of Spring cloud and Consul and I wonder if there is way to exchange data and state between instance the same of a microservice.

For example, I have AuthenticationService1 (AS1) and AuthenticationService2 (AS2). When a user comes to AS1, he logs in, receives a token and next time he comes it's only verified. But at this moment AS2 is not aware of the state of AS1.

I saw ideas about using a database table where information about user sessions is stored, but maybe there is an easier way for AS1 to share its state with AS2 or to send a message about log in?

Upvotes: 0

Views: 91

Answers (1)

wargre
wargre

Reputation: 4753

Consul is a service management (discovery, config, ...), not a cache / pub-sub system.

You may want to use a shared cache behind the scene for your use case. You AS1 service authenticate a user, then put in the cache the token. AS2 can retrieve the token in the cache. For that, you can use application like

  • redis
  • hazelcast
  • infinispan
  • ... other stuff like store data in a DB ...

You can also use a pub-sub system and a local cache for each ASx, but you can have issue when on AS restart (cache lost). So from my point of view, shared cache is better.

Upvotes: 1

Related Questions