lerenn / asyncapi-codegen

An AsyncAPI Golang Code generator that generates all Go code from the broker to the application/user. Just plug your application to your favorite message broker!
Apache License 2.0
82 stars 22 forks source link

✨ add NATS JetStream broker #121

Closed stefanmeschke closed 7 months ago

stefanmeschke commented 7 months ago

Changes?

Why?

Resolves https://github.com/lerenn/asyncapi-codegen/issues/109

lerenn commented 7 months ago

When I try to run the "ping" example with the natsjetstream, I run over the error:

panic: nats: no responders available for request

It seems to be that this error is returned by the ConsumeIfNeeded function, because it's trying to listen to a stream that doesn't have publishers (yet), as I start the app before the user.

I initialized the broker with the following lines:

broker := natsjetstream.NewController(
        "nats://nats-jetstream:4222",     // Set URL to broker
        natsjetstream.WithLogger(logger), // Attach an internal logger
        natsjetstream.WithStream("ping"), // Set the stream used
        natsjetstream.WithStreamConfig(jetstream.StreamConfig{
            Name: "ping",
        }),
    )

If you have any idea of what I could do to resolve it, I'm interested. Otherwise, I'll continue to search.

Edit: Okay, I was missing the consumer config. I'm a real Jetstream newbie :laughing:

I'll add it to the examples!

lerenn commented 7 months ago

I took the liberty to add a 'ping' example with the commit 799cecb4484e648196242539b2d23721c887e821. As I was testing the broker, I though it would still be interesting to add it!

That said, it works like a charm! :pray:

Clearly I don't have a lot to add except the comments that I already did. Feel free to mark it as ready when you are !

I'll add the broker to the tests (in test directory) in another MR to not bother you with them :relieved: