dotnetcore / CAP

Distributed transaction solution in micro-service base on eventually consistency, also an eventbus with Outbox pattern
http://cap.dotnetcore.xyz
MIT License
6.61k stars 1.28k forks source link

Error in Nats transport #1529

Closed Wagimo closed 4 months ago

Wagimo commented 4 months ago

Hello. I am trying to use CAPS with NATS but have not succeeded to date. I have configured a simple test project where it configures the connection with the NATS server through the IoC, but when I run the App, it always gives me the following error:

NATS.Client.NATSTimeoutException: Timeout occurred. at NATS.Client.Connection.RequestSyncImpl(String subject, MsgHeader headers, Byte[] data, Int32 offset, Nullable1 count, Int32 timeout) at NATS.Client.Connection.Request(String subject, Byte[] data, Int32 timeout) at NATS.Client.JetStream.JetStreamBase.RequestResponseRequired(String subject, Byte[] bytes, Int32 timeout) at NATS.Client.JetStream.JetStreamBase.GetStreamInfoInternal(String streamName, StreamInfoOptions options) at NATS.Client.JetStream.JetStreamManagement.GetStreamInfo(String streamName) at DotNetCore.CAP.NATS.NATSConsumerClient.FetchTopics(IEnumerable1 topicNames) at DotNetCore.CAP.Internal.ConsumerRegister.Execute() at DotNetCore.CAP.Internal.ConsumerRegister.Start(CancellationToken stoppingToken) at DotNetCore.CAP.Internal.Bootstrapper.BootstrapCoreAsync() DotNetCore.CAP.Processor.CapProcessingServer: Information: Starting the processing server.

What am I doing wrong? How can I use CAPS with NATS? Do you have any example implementation for .Net core 8? thank you.

yang-xiaodong commented 4 months ago

Did you enable JetStream when NATS starting ?

PS D:\nats-server-v2.10.14-windows-amd64> .\nats-server.exe -js
Wagimo commented 4 months ago

Hello, I appreciate your collaboration. Yes, I was indeed not enabling JetStream. Now the communication is active. But when I send a message from NestJS, I do it using a simple Pattern ('createproduct') and in the .netcore client I receive a message that says the following:

DotNetCore.CAP.Internal.ConsumerRegister[0] An exception occurred when process received message. Message:'DotNetCore.CAP.Messages.TransportMessage'. System.Collections.Generic.KeyNotFoundException: The given key 'cap-msg-id' was not present in the dictionary. at DotNetCore.CAP.Internal.ConsumerRegister.<>c__DisplayClass22_0.<b__0>d.MoveNext()

I understand that a key must be sent as a dictionary, but I cannot find in the official documentation what format should be used for NATS when messages are published nor do I see anything related to NATS Server in the code examples. By any chance do you have a project that uses nats to guide me? Thank you so much

El lun, 13 may 2024 a las 20:44, Savorboard @.***>) escribió:

Did you enable JetStream when NATS starting ?

PS D:\nats-server-v2.10.14-windows-amd64> .\nats-server.exe -js

— Reply to this email directly, view it on GitHub https://github.com/dotnetcore/CAP/issues/1529#issuecomment-2109120778, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADBNKGRVPS245TAYSTPUELTZCFUAPAVCNFSM6AAAAABHVB3AW6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBZGEZDANZXHA . You are receiving this because you authored the thread.Message ID: @.***>

-- Walter Molano System Web Developer.

yang-xiaodong commented 4 months ago

See #1519 , NATS does not provide CustomHeadersBuilder option for heterogeneous system messages, Would you want to make a PR for it like Kafka?

yang-xiaodong commented 4 months ago

Fixed in #1519