Vladimir
Vladimir

Reputation: 1694

TCP connection/configuration to Event Store issue

Following this great book on DDD and event sourcing by Alexey Zimarev, I am going through the code examples, and coding the same concepts on a different domain. Trying to run the dockerized example, with one .NET Core API and Event Store database, I am able to start everything correctly, I go to Event Store UI app, and there I can see that my API managed to initialize the connection to the Event Store: Event Store UI

However, when I try to connect to the Event Store from the Controller/Service code, trying to read event stream, I am getting an "error": "Item Operation ReadEventOperation... reached retries limit : 10 ... "stackTrace": " at EventStore.ClientAPI.Internal.EventStoreNodeConnection.ReadEventAsync ...

My appsettings:

  "eventStore": {
    "connectionString": "ConnectTo=tcp://admin:[email protected]:1113; DefaultUserCredentials=admin:changeit; HeartBeatTimeout=500"

docker-compose.yml eventstore service:

    services:
    
      eventstore:
        container_name: esskipass-eventstore
        image: eventstore/eventstore
        command: --dev --enable-external-tcp --ext-ip=0.0.0.0 --int-ip=0.0.0.0 --disable-external-tcp-tls
        environment:
          - EVENTSTORE_CLUSTER_SIZE=1
          - EVENTSTORE_INT_TCP_PORT=1112
          - EVENTSTORE_EXT_TCP_PORT=1113
          - EVENTSTORE_INT_HTTP_PORT=2112
          - EVENTSTORE_EXT_HTTP_PORT=2113
          - EVENTSTORE_DEV=true
        ports:
          - "1112:1112"
          - "1113:1113"
          - "2112:2112"
          - "2113:2113"
...

and Event Store logs:

    ...
[ 1,17,20:59:11.046,INF] External TCP connection accepted: [Normal, "172.20.0.1:54850", L"172.20.0.2:1113", {81629828-c448-49a0-8e99-6fb8803f3928}].

[ 1,21,20:59:12.509,INF] ES "TcpConnection" closed [20:59:12.508: N"172.20.0.1:54850", L"172.20.0.2:1113", {81629828-c448-49a0-8e99-6fb8803f3928}]:Received bytes: 312, Sent bytes: 0

[ 1,21,20:59:12.509,INF] ES "TcpConnection" closed [20:59:12.509: N"172.20.0.1:54850", L"172.20.0.2:1113", {81629828-c448-49a0-8e99-6fb8803f3928}]:Send calls: 0, callbacks: 0

[ 1,21,20:59:12.509,INF] ES "TcpConnection" closed [20:59:12.509: N"172.20.0.1:54850", L"172.20.0.2:1113", {81629828-c448-49a0-8e99-6fb8803f3928}]:Receive calls: 2, callbacks: 2

[ 1,21,20:59:12.509,INF] ES "TcpConnection" closed [20:59:12.509: N"172.20.0.1:54850", L"172.20.0.2:1113", {81629828-c448-49a0-8e99-6fb8803f3928}]:Close reason: [Success] "Socket closed"

[ 1,21,20:59:12.510,INF] Connection '"external-normal"""' ["172.20.0.1:54850", {81629828-c448-49a0-8e99-6fb8803f3928}] closed: Success.

[ 1, 6,20:59:12.511,DBG] Persistent subscription lost connection from "172.20.0.1:54850"

[ 1,21,20:59:12.718,INF] External TCP connection accepted: [Normal, "172.20.0.1:54870", L"172.20.0.2:1113", {45da7e67-2f2b-422b-a1eb-28339c685205}].

[ 1,10,20:59:17.735,DBG] Closing connection '"external-normal"""' ["172.20.0.1:54870", L"172.20.0.2:1113", {45da7e67-2f2b-422b-a1eb-28339c685205}] cleanly." Reason: HEARTBEAT TIMEOUT at msgNum 1"

[ 1,10,20:59:17.735,INF] ES "TcpConnection" closed [20:59:17.735: N"172.20.0.1:54870", L"172.20.0.2:1113", {45da7e67-2f2b-422b-a1eb-28339c685205}]:Received bytes: 312, Sent bytes: 22

[ 1,10,20:59:17.735,INF] ES "TcpConnection" closed [20:59:17.735: N"172.20.0.1:54870", L"172.20.0.2:1113", {45da7e67-2f2b-422b-a1eb-28339c685205}]:Send calls: 1, callbacks: 1

[ 1,10,20:59:17.735,INF] ES "TcpConnection" closed [20:59:17.735: N"172.20.0.1:54870", L"172.20.0.2:1113", {45da7e67-2f2b-422b-a1eb-28339c685205}]:Receive calls: 2, callbacks: 1

[ 1,10,20:59:17.735,INF] ES "TcpConnection" closed [20:59:17.735: N"172.20.0.1:54870", L"172.20.0.2:1113", {45da7e67-2f2b-422b-a1eb-28339c685205}]:Close reason: [Success] "HEARTBEAT TIMEOUT at msgNum 1"

[ 1,10,20:59:17.736,INF] Connection '"external-normal"""' ["172.20.0.1:54870", {45da7e67-2f2b-422b-a1eb-28339c685205}] closed: Success.

[ 1,21,20:59:17.736,DBG] Persistent subscription lost connection from "172.20.0.1:54870"

[ 1, 6,20:59:17.912,INF] External TCP connection accepted: [Normal, "172.20.0.1:54878", L"172.20.0.2:1113", {5c21a809-26be-42b7-b979-b2e6532d508d}].

[ 1,10,20:59:22.926,DBG] Closing connection '"external-normal"""' ["172.20.0.1:54878", L"172.20.0.2:1113", {5c21a809-26be-42b7-b979-b2e6532d508d}] cleanly." Reason: HEARTBEAT TIMEOUT at msgNum 1"

[ 1,10,20:59:22.927,INF] ES "TcpConnection" closed [20:59:22.926: N"172.20.0.1:54878", L"172.20.0.2:1113", {5c21a809-26be-42b7-b979-b2e6532d508d}]:Received bytes: 312, Sent bytes: 22

    ...

First I've found out that without command: --dev --enable-external-tcp --ext-ip=0.0.0.0 --int-ip=0.0.0.0 --disable-external-tcp-tls my Event Store wouldn't start, TCP port would start disabled. Then I've tried with setting different ports, HeartbeatTimeout, HeartbeatInterval ..., and some other connection settings customizations. Event Store and event sourcing are a new ground to me, so it may be that I am missing some basic customization here.

Appreciate any help or advice.

Upvotes: 2

Views: 2197

Answers (2)

Brian Richardson
Brian Richardson

Reputation: 552

I was able to get the code in Chapter 10 working on a locally installed instance (not Docker) with TLS, by using the initialization in Program.cs:

var connStr = builder.Configuration["eventStore:connectionString"];
var esConnection = EventStoreConnection.Create(
    connStr,
    ConnectionSettings.Create().DisableServerCertificateValidation().KeepReconnecting(),
    builder.Environment.ApplicationName);
var store = new EsAggregateStore(esConnection);

Note the addition of DisableServerCeritifcateValidation().

Upvotes: 0

Alexey Zimarev
Alexey Zimarev

Reputation: 19630

The book code uses the TCP protocol and targets EventStoreDB 5, so you have two choices. The easiest way is to change the image that your compose file uses:

image: eventstore/eventstore:release-5.0.8

If you want to use v20.6, the easiest way would be to use the 20.6.1 preview in insecure mode:

version: '3.4'

services:
  eventstore.db:
    image: docker.pkg.github.com/eventstore/eventstore/eventstore:20.6.1-alpha.0.40-buster-slim
    environment:
      - EVENTSTORE_CLUSTER_SIZE=1
      - EVENTSTORE_RUN_PROJECTIONS=All
      - EVENTSTORE_START_STANDARD_PROJECTIONS=true
      - EVENTSTORE_EXT_TCP_PORT=1113
      - EVENTSTORE_EXT_HTTP_PORT=2113
      - EVENTSTORE_INSECURE=true
      - EVENTSTORE_ENABLE_ATOM_PUB_OVER_HTTP=true
    ports:
      - "1113:1113"
      - "2113:2113"
    volumes:
      - type: volume
        source: eventstore-volume-data
        target: /var/lib/eventstore
      - type: volume
        source: eventstore-volume-logs
        target: /var/log/eventstore

volumes:
  eventstore-volume-data:
  eventstore-volume-logs:

You would need to login to the GitHub registry once before starting compose. You'd need to get the personal access token in GitHub and then use it as the password for docker login. The user name is your GitHub account email.

docker login docker.pkg.github.com -u [email protected] -p mytoken

Upvotes: 2

Related Questions