Persistence for cosmosDB



hey all. i’m changing now my mongo to work with cosmosDB and i have a problem with the nsb Persistence for the cosmosDB. i want to know how can i connect my application to the cosmosDB with nsb persistence.
here is my code:
configuration.UsePersistence<MongoDBPersistence().SetDatabaseName(“NSBPersistence”); configuration.UsePersistence<MongoDBPersistence().SetConnectionString(cosmosDBConnectionString);

thank you.

(Simon Cropp) #2

i would assume it is abandoned and, IMO, dont use if for a production system with first clarifying the current project status.

(Simon Cropp) #3

sorry i forgot there are two mongo persister projects. the other one looks maintained


thank you for the answer, but it didnt help me as i already use this code in my project.
im trying to understand how to use persistence with cosmosDB, because the behavior looks different when im trying to connect locally and to the cosmos.
when im connecting locally there are no problems but when im setting the cosmos conncetion string i get the error that relates to the persistence.

(Mauro Servienti) #5

@danielito can you post details about the error you’re getting?



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.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization)
— End of stack trace from previous location where exception was thrown —

when i remove the part of the persistence i didn’t get errors.

(Mauro Servienti) #7

Sounds like a purely authentication issue. Check if this helps


thank you for the answer.
the problem is not the authentication as when i remove the part of the persistence i succeed to connect the cosmosDB. the problem is with the persistence.
the code is:
configuration.UsePersistence<MongoDBPersistence().SetDatabaseName(“NSBPersistence”); configuration.UsePersistence<MongoDBPersistence().SetConnectionString(username:password@host:port/?ssl=true&replicaSet=globaldb);

Azure Cosmos DB has strict security requirements and standards. Azure Cosmos DB accounts require authentication and secure communication via SSL.

(Mauro Servienti) #9

Hi @danielito,

I tried to setup a project using MongoDB Persistence from connecting to a newly created CosmosDB instance. My endpoint startup code is the following:

var configuration = new EndpointConfiguration("MongoCosmos");
var persistence = configuration.UsePersistence<MongoDBPersistence>();

var endpoint = await Endpoint.Start(configuration);

(connection string contains a fake key)

Everything worked as expected and if I try to kick off a saga I can see data stored in CosmosDB using the Azure Portal Data Explorer.

Can you double check that your connection string is in the correct format?



(Simon Cropp) #10

perhaps a sample would be useful :wink:


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!