Persistence for cosmosDB

azureservicebus
azurepersistence

#1

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.


(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 https://github.com/sbmako/NServiceBus.MongoDB/


#4

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?

.m


#6

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.


(Mauro Servienti) #7

Sounds like a purely authentication issue. Check if this helps https://stackoverflow.com/questions/31314245/a-timeout-occured-after-30000ms-selecting-a-server-using-compositeserverselector


#8

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.


(Mauro Servienti) #9

Hi @danielito,

I tried to setup a project using MongoDB Persistence from https://github.com/sbmako/NServiceBus.MongoDB 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


(Simon Cropp) #10

perhaps a sample would be useful :wink:


#11

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

.m


#13

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

( connection string contains a fake key )


(Mauro Servienti) #14

@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


#15

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.


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

Cheers,
.m


#17

ok. thank you very much!