Hello, I am using mongodb as the Rebus transport. When I use pub/sub, two consumers subscribe to the same topic, and then when I use the producer to send an event, it will prompt id conflict,It generates two identical messages, including the same id.
System.AggregateException: Messages sent were not unique (Cannot send message with ID 4ab31b8c-da85-4a6f-ac24-fb482c954f34 because a message already exists with that ID)
---> Rebus.MongoDb.Transport.Exceptions.UniqueMessageIdViolationException: Cannot send message with ID 4ab31b8c-da85-4a6f-ac24-fb482c954f34 because a message already exists with that ID
--- End of inner exception stack trace ---
this is my producer code:
// builder
builder.Services.AddRebus(configure => configure
.Logging(l => l.ColoredConsole(Rebus.Logging.LogLevel.Info)).Transport(t => t.UseMongoDb(new MongoDbTransportOptions(mongoUrl), "producer"))
.Subscriptions(s => s.StoreInMongoDb(mongoDatebase, "testMessageEvent", true))
.Serialization(s => s
.UseCustomMessageTypeNames()
.AddWithShortName(typeof(TestMessageEvent)))
.Routing(r => r
.TypeBased()
.MapAssemblyOf<OrderCreated>("testMessage")
.Map<TestMessageEvent>("testMessage"))
);
// app
app.Services.UseRebus(r => r.Advanced.Topics.Subscribe("producerTest"));
// send message
await _bus.Advanced.Topics.Publish("producerTest", new TestMessageEvent(Guid.NewGuid().ToString(), "test"));
this is my consumer code:
// builder
builder.Services.AddRebus(configure => configure
.Logging(l => l.ColoredConsole(Rebus.Logging.LogLevel.Info)).Transport(t => t.UseMongoDb(new MongoDbTransportOptions(mongoUrl), "consumer"))
.Subscriptions(s => s.StoreInMongoDb(mongoDatebase, "testMessageEvent", true))
.Serialization(s => s
.UseCustomMessageTypeNames()
.AddWithShortName(typeof(TestMessageEvent)))
.Routing(r => r
.TypeBased()
.MapAssemblyOf<OrderCreated>("testMessage")
.Map<TestMessageEvent>("testMessage"))
);
// app
app.Services.UseRebus(r => r.Advanced.Topics.Subscribe("producerTest"));
and this my mongodb data from testMessageEvent:
{
"_id": "producerTest",
"addresses": [
"producer",
"consumer"
]
}
in Rebus.MongoDb.Transport.MongoDbMessageProducer
I don't know Rebus well, so I don't know why it's doing this here, is there any reason?
![image-20230824184300675](https://private-user-images.githubusercontent.com/38344678/262950181-a8a450c5-8356-4e28-9e4e-bc01bf90d955.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM2NTczMjUsIm5iZiI6MTcyMzY1NzAyNSwicGF0aCI6Ii8zODM0NDY3OC8yNjI5NTAxODEtYThhNDUwYzUtODM1Ni00ZTI4LTllNGUtYmMwMWJmOTBkOTU1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE0VDE3MzcwNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTJhY2I1ZWNmZWE0MmYwNmRlM2FhNzBkYTgwZDJhYjRlYzMzMmNiMjdjOTFhZjY5ZWRkNzBlOWM4ZDgzYTQxZjgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.rRsMsEbzeRrmYs96J6uxzBBXBYNyNKAxFHvonclSO_Q)