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.UseTransport();
configuration.UsePersistence<MongoDBPersistence().SetDatabaseName(“NSBPersistence”); configuration.UsePersistence<MongoDBPersistence().SetConnectionString(cosmosDBConnectionString);

thank you.
daniel.

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

sorry i forgot there are two mongo persister projects. the other one looks maintained GitHub - sbmako/NServiceBus.MongoDB: MongoDB persistence for NServiceBus

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.

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

.m

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/daniel.documents.azure.com:10255” }”, EndPoint: “Unspecified/daniel.documents.azure.com:10255”, 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.

Sounds like a purely authentication issue. Check if this helps c# - A timeout occured after 30000ms selecting a server using CompositeServerSelector - Stack Overflow

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.UseTransport();
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.

Hi @danielito,

I tried to setup a project using MongoDB Persistence from GitHub - sbmako/NServiceBus.MongoDB: MongoDB persistence for NServiceBus connecting to a newly created CosmosDB instance. My endpoint startup code is the following:

var configuration = new EndpointConfiguration("MongoCosmos");
configuration.UseTransport<LearningTransport>();
configuration.SendFailedMessagesTo("error");
var persistence = configuration.UsePersistence<MongoDBPersistence>();
persistence.SetDatabaseName("nsb-data");
persistence.SetConnectionString(@"mongodb://mauro-nsb-tests:xmdvdsihjfbvkdfjbvkdsjfbvkdsfjbvdfvndfvjndfvjndkfj==@mauro-nsb-tests.documents.azure.com:10255/?ssl=true&replicaSet=globaldb");

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?

mongodb://resource:key@server:port/?ssl=true&replicaSet=globaldb

.m

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.

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

.m

1 Like

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

( connection string contains a fake key )

@danielito

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

Cheers,
.m

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.
daniel.

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.

Cheers,
.m

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.

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/daniel.documents.azure.com:10255” }”, EndPoint: “Unspecified/daniel.documents.azure.com:10255”, 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 —