Azure / azure-event-hubs-emulator-installer

This repository acts as a central hub for handling issues, collecting feedback, and facilitating discussions related to the Azure Event Hubs emulator.
https://learn.microsoft.com/azure/event-hubs/overview-emulator
MIT License
15 stars 5 forks source link

Not able to connect from other containers in docker-compose #11

Open krystianolech opened 1 month ago

krystianolech commented 1 month ago

Describe the bug It is not possible to comunicate to emulator form other docker services. It works fine for emulator started over docker to locally running services, but it does not work on docker network

To Reproduce Minimal reproduction issue: https://github.com/krystianolech/event-hub-emulator-issue

If we would run this docker-compose (docker-compose up -d) and then run local nodejs script, message are publihed. However same service within docker is not able to send message and is hanging while trying to send message. For local connection string is used: Endpoint=sb://localhost;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;EntityPath=eh1;UseDevelopmentEmulator=true; while in docker endpoint is changed to name of container with emulator: sb://eventhubs-emulator;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;EntityPath=eh1;UseDevelopmentEmulator=true;

I tried both Endpoint=sb://eventhubs-emulator and Endpoint=sb://emulator. Setting any name give ENOTFOUND error so its clear that service is connecting to emulator container

Docker Version: Docker version 26.1.1, build 4cf5afa

Arguments && Environment variables to start Emulator:

Emulator Launch Method:

krishankumar95 commented 1 month ago

@krystianolech This is related to: https://github.com/Azure/azure-event-hubs-emulator-installer/issues/9

As a working alternative you can try out the following setup:

name: "eventhubs-emulator-with-containerized-app"
services:
  azurite:
    image: mcr.microsoft.com/azure-storage/azurite
    network_mode: host

  emulator:
    image: mcr.microsoft.com/azure-messaging/eventhubs-emulator:latest
    volumes:
      - "./Config.json:/Eventhubs_Emulator/ConfigFiles/Config.json"
    environment:
      BLOB_SERVER: localhost
      METADATA_SERVER: localhost
      ACCEPT_EULA: "N"
    network_mode: host
    depends_on:
      - azurite

  sample-containerized-app:
    build:
      context: .
      dockerfile: ./Dockerfile
    network_mode: host
    depends_on:
      - emulator

Few things to note:

a) EULA Flag

b) Connection string used :

"Endpoint=sb://localhost;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;EntityPath=eh1;UseDevelopmentEmulator=true;"

c) Sample application should wait for few seconds to allow Emulator to bootup and accept requests

krystianolech commented 1 month ago

thank you for the update!

Unfortunately it would not work best for my uescase as I have more containers with conflicting ports in that docker-compose file so it would would require more adjustments to separate ports. Do you know if making it possible to use different host is on a rode map for simulator and when approximately it would be available?

krishankumar95 commented 1 month ago

Triaged, assigning to @Saglodha to assist with the roadmap/milestone for next release.

AlthalusDGr8 commented 1 month ago

Running into a similar issue. When packaging event hubs emulator along with other services in our software stack, we keep getting connection refused errors. Trying to change it from localhost to anything else we get the following: The Event Hubs emulator is only available locally. The endpoint must reference to the local host. (Parameter 'connectionString')

krishankumar95 commented 1 month ago

@AlthalusDGr8; Which language and version of EH Client SDK are we using? This seems like an error from client SDK side.

This check exists in initial versions of SDKs which started out supporting Emulator, upgrading to latest SDK version along with host networking workaround mentioned above should allow you to use the Emulator meanwhile the patch rolls around for this issue.

AlthalusDGr8 commented 1 month ago

@AlthalusDGr8; Which language and version of EH Client SDK are we using? This seems like an error from client SDK side.

This check exists in initial versions of SDKs which started out supporting Emulator, upgrading to latest SDK version along with host networking workaround mentioned above should allow you to use the Emulator meanwhile the patch rolls around for this issue.

Tried with both version 5.11.2 and 5.11.3, get the same error (just to be sure, we are using this lib: Azure.Messaging.EventHubs).

As for using the hosts we want to avoid doing so for the time being, so we keep network isolation like the other containers. We shall wait for the patch and see how it goes from there.

piwo1984 commented 1 month ago

Same here. I'm working on a PoC including Debezium and Azure Event Hub. My goal is to get a local "installation" of MariaDB, Debezium and Azure Event Hub Emulator. For this I tried a docker compose setup but the debezium container isn't able to connect to the emulator container.

Saglodha commented 3 weeks ago

@krystianolech / @piwo1984 - Thanks for bringing this to our attention. Our team is working on fixing above-described behavior. We expect the fix to be shipped with upcoming milestone.

krishankumar95 commented 6 days ago

Hi everyone, this issue has been patched with the latest release: 1.2.4-preview

Other containers on the same bridge network can now interact with Emulator using the container alias or IP. Example connection string below assuming the name of Emulator container is unchanged in default docker compose and is "eventhubs-emulator" :

"Endpoint=sb://eventhubs-emulator;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true;"

Additionally, if containers are different bridge networks "host.docker.internal" can be used as host in the connection string.

"Endpoint=sb://host.docker.internal;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=SAS_KEY_VALUE;UseDevelopmentEmulator=true;"

Latest client SDKs need to be used to allow for non-localhost connections with Emulator.

mr-panucci commented 5 days ago

Just tested with 1.2.4-preview and works great - thanks!

AlthalusDGr8 commented 4 days ago

Confirmed that it worked for me as well thanks