Persistence for cosmosDB



hey. thank you for your help.
i tried to connect with this format and with your example and yet i couldn’t connect to the cosmos through the application.

(Mauro Servienti) #12

Would you be able to share your code? For example in a GitHub repo



its a bit problem to share it with GITHube repo.
ill send you my code.

( connection string contains a fake key )

(Mauro Servienti) #14


your code works fine here. The only thing I cannot try are the custom mutators. Can you post the mutators code as well?



hey @mauroservienti.
we found the problem.
we had to enable the tls 1.2 protocol.
my question is if nsb persistence for mongo can work with tls 1.2 and if so how can i set it?
thank you.

(Mauro Servienti) #16

Thanks for the feedback @danielito. I think that that’s a question for the NServiceBus.MongoDB people. I suggest to raise an issue with them.
My gut feeling is that it’s not a NServiceBus.MongoDB related thing but it’s more related to the MongoDB client driver.



ok. thank you very much!


hey. after fix the issue with tls 1.2 we still having issue with mongodb persistence. we are using mongodb driver 2.4. i dont know why but only when we are using mongodb persistence we are facing issue.

(Mauro Servienti) #19

Can you provide more details about the issues you’re facing?


i tried connect to the local mongo that we are working with and i didnt have any issues. but unfortunately when i replaced the configuration to work with the cosmosdb i got this error: System.TimeoutException: A timeout occured after 30000ms selecting a server using CompositeServerSelector{ Selectors = MongoDB.Driver.MongoClient+AreSessionsSupportedServerSelector, LatencyLimitingServerSelector{ AllowedLatencyRange = 00:00:00.0150000 } }. Client view of cluster state is { ClusterId : “1”, ConnectionMode : “ReplicaSet”, Type : “ReplicaSet”, State : “Disconnected”, Servers : [{ ServerId: “{ ClusterId : 1, EndPoint : “Unspecified/” }”, EndPoint: “Unspecified/”, State: “Disconnected”, Type: “Unknown”, HeartbeatException: "MongoDB.Driver.MongoConnectionException: An exception occurred while opening a connection to the server. —> System.IO.IOException: Authentication failed because the remote party has closed the transport stream.
at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)
at System.Threading.Tasks.TaskFactory 1.FromAsyncCoreLogic(IAsyncResult iar, Func 2 endFunction, Action 1 endAction, Task 1 promise, Boolean requiresSynchronization)
— End of stack trace from previous location where exception was thrown —


i checked also the connection string and it is ok. when i removed the “MongoDBPersistence” i could connect.


someone have solution for this?

(Mauro Servienti) #23

Based on the above my hunch is that the problem is on the CosmosDB side. Googling for the error it seems you are not alone, there are users (that are not using NServiceBus) facing the same issue when trying to connect to a CosmosDB replica-set using the MongoDB flavor.

I’m not sure what we can do, here. If I try a sample that uses the MongoDB community persistence connected to a CosmosDB instance it just works. There might be things in your local network configuration that are preventing the communication to happen (as there were before with TLS configuration), or it might really be a CosmosDB thing.

As previously suggested you should also get in touch with the NServiceBus.MongoDB mantainers, raising an issue with them, they might have already faced similar issues.



thank you for your answer. can you show me your example? which mongo driver and nsb version you use?

(Mauro Servienti) #25

What’s the best way to share it with you?


i think the best way will be in git. thank you.

(Mauro Servienti) #27

Here you go


thank you. unfortunately we are working with nsb 5.2.12 version and with this version we cannot connect. upgrade the nsb version will be a problem for us right now.

(Mauro Servienti) #29

that’s a news :slight_smile:
I suspect that there isn’t much you can do, the MongoDB Persistence fo NServiceBus V5 probably uses an old version of the MongoDB Client that is not fully supported by CosmosDB.

As said you should raise an issue with the Community MongoDB Persistence maintainers to see if there is anything that can be done.

(Mauro Servienti) #30

@danielito could you please help us in better understanding your Azure Cosmos DB usage by answering this short survey?