Giter VIP home page Giter VIP logo

Comments (5)

mikecann avatar mikecann commented on August 24, 2024

Am I missing something? Im using the TS example listed on the readme..

import {
  EventStoreDBClient,
  jsonEvent,
  FORWARDS,
  START,
  JSONEventType,
} from "@eventstore/db-client";

const client = new EventStoreDBClient({
  endpoint: "localhost:2113",
});

interface Reservation {
  reservationId: string;
  movieId: string;
  userId: string;
  seatId: string;
}

type SeatReservedEvent = JSONEventType<
  "seat-reserved",
  {
    reservationId: string;
    movieId: string;
    userId: string;
    seatId: string;
  }
>;

type SeatChangedEvent = JSONEventType<
  "seat-changed",
  {
    reservationId: string;
    newSeatId: string;
  }
>;

type ReservationEvents = SeatReservedEvent | SeatChangedEvent;

async function simpleTest(): Promise<void> {
  const streamName = "booking-abc123";

  const event = jsonEvent<SeatReservedEvent>({
    type: "seat-reserved",
    data: {
      reservationId: "abc123",
      movieId: "tt0368226",
      userId: "nm0802995",
      seatId: "4b",
    },
  });

  const appendResult = await client.appendToStream(streamName, event);

  const events = client.readStream<ReservationEvents>(streamName, {
    fromRevision: START,
    direction: FORWARDS,
    maxCount: 10,
  });

  const reservation: Partial<Reservation> = {};

  for await (const { event } of events) {
    switch (event.type) {
      case "seat-reserved": {
        reservation.reservationId = event.data.reservationId;
        reservation.movieId = event.data.movieId;
        reservation.seatId = event.data.seatId;
        reservation.userId = event.data.userId;
        break;
      }
      case "seat-changed": {
        reservation.seatId = event.data.newSeatId;
        break;
      }
      default: {
        const _exhaustiveCheck: never = event;
        break;
      }
    }
  }
}

And the exact same installation method listed on the official docs: https://developers.eventstore.com/server/v5/installation.html#use-docker-compose

from eventstore-client-nodejs.

George-Payne avatar George-Payne commented on August 24, 2024

Hi Mike,

insecure docker compose
[...]

const client = new EventStoreDBClient({
  endpoint: "localhost:2113",
 });

The grpc clients are secure by default, so you need to tell the client to use an insecure connection, you can either do this via the options argument:

const client = new EventStoreDBClient(
  { endpoint: "localhost:2113" },
  { insecure: true }
);

or via a connection string

const client = EventStoreDBClient.connectionString`esdb://localhost:2113?tls=false`;

You can find our connecting string helper here:

https://developers.eventstore.com/clients/grpc/#connection-details


And the exact same installation method listed on the official docs:
https://developers.eventstore.com/server/v5/installation.html#use-docker-compose

You've linked the v5 docs here (though you linked v21.10 in the original issue)

The GRPC clients are only supported on 20.6.1 upwards.


If you're having trouble finding something in the docs, a good place to look for examples are the tests in this repo. For example, under connection/insecure


This could definitely be more explicitly spelled out in the documentation (and isn't the first issue we've had asking this so it must be tripping more people up.) I'll see about adding something.

from eventstore-client-nodejs.

mikecann avatar mikecann commented on August 24, 2024

Ah gotcha thanks, I can confirm since adding { insecure: true } it now works.

I definately think this could be made more clear in the docs or perhaps the error could be more clear UnavailableError: 14 UNAVAILABLE: No connection established doesnt really tell you much ;)

If you're having trouble finding something in the docs, a good place to look for examples are the tests in this repo. For example, under connection/insecure

Although linking to tests is sometimes useful in this case it doesnt actually show me where I made a mistake as it doesnt show me that I needed to use the special flag:

image

Also I would have had to go looking for the "insecure" examples which would probably have meant I knew that I was getting a security issue, which I didnt know because of the error.

Anyways I appreciate you getting back to me, I have solved the issue so feel free to close this.

from eventstore-client-nodejs.

George-Payne avatar George-Payne commented on August 24, 2024

I can confirm since adding { insecure: true } it now works.

Great, glad you were able to get it working.

I definately think this could be made more clear in the docs

I've added a note to the top of the docs about this to hopefully point people in the right direction. EventStore/documentation#544

perhaps the error could be more clear UnavailableError: 14 UNAVAILABLE: No connection established doesnt really tell you much

Setting the client to insecure changes the endpoint from https:// to http:// so the returned error is just connection refused, meaning we can't distinguish between an incorrect endpoint, or an unavailable server, or a spelling mistake in your endpoint etc. Maybe we could add a debug log with some pointers on what to check.

I have solved the issue so feel free to close this.

Will do.

from eventstore-client-nodejs.

alfonsodev avatar alfonsodev commented on August 24, 2024

I Had the same problem as @mikecann, It's obviously nice that is secure by default, I think it would be better to add a comment on the example code, since different people arrive to this repo from different places.
And it's most likely that you are running that "hello world" in an insecure way, since I might wrong but all docker examples from the getting started guides are written with --insecure

from eventstore-client-nodejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.