bitsofinfo / hazelcast-docker-swarm-discovery-spi

Docker Swarm based discovery strategy SPI for Hazelcast enabled applications
Apache License 2.0
39 stars 33 forks source link

Shared Hazelcast Instances Between Multiple Microservices #13

Closed tunix closed 6 years ago

tunix commented 6 years ago

Hi @bitsofinfo ,

I've a use case where N microservices start their own Hazelcast instances and form a cluster. I have some shared data between 2 different microservices. However since they're different microservices, I define them seperately in my swarm config and due to service_name being mandatory, they won't be able to find each other.

service_a:
    ...
    DOCKER_HOST: ...
    ...network_name: internal
    ...service_name: service_a
    ...

service_b:
    ...
    ...network_name: internal
    ...service_name: service_b
    ...

I think below would work instead where I don't define the service name but the service labels. (Question: I don't see an example for adding service labels, does this plugin look for keys or values?)

service_a:
    ...
    DOCKER_HOST: ...
    ...network_name: internal
    ...service_labels: hazelcast
    deploy:
        labels:
            hazelcast: true
    ...

service_b:
    ...
    ...network_name: internal
    ...service_labels: hazelcast
    deploy:
        labels:
            hazelcast: true
    ...

I think we can make service names optional as well and check during runtime whether a service name or service label exists. What do you think?

tunix commented 6 years ago

Looking at the code, I can see that this was the intended behaviour. (ex: SwarmAddressPicker @ L24, SwarmDiscoveryUtil @ L111-112 , tag: 1.0-RC3) So I think we can make this change?

bitsofinfo commented 6 years ago

Both (service names and service labels args) accept multiple names (comma delimited) I use this functionality today. Neither should be required I thought, but sure please do a PR + README update if you'd like that behavior.

tunix commented 6 years ago

Sent PR #15

bitsofinfo commented 6 years ago

1.0-RC7 is out, thx!