NServiceBus 6 with Web Api

Hi,

I’m new to NServiceBus 6 and I want to use NServiceBus to synchronize two or more web api’s
I am not using Asp.Net Core but .Net framework 4.6.1
I want to configure the EndpointConfiguration in the App_Start and in a controller I want to publish a message to a subscriber,
but I don’t have an instance of the EndpointConfiguration in the controller. How do I solve this? Is there a sample?
I looked at the CoreWebAPI but that didn’t helped me.

Hi Jacques,

Thanks for reaching out. Can you explain a bit more your scenario when you say “I want to use NServiceBus to synchronize two or more WebApis”? What kind of data are you planing to synchronize?

The EndpointConfiguration object is only used to create an instance of an endpoint. You pass that object into Endpoint.Start(). That gives you back an endpoint / message session instance. That message session instance is the “communication object” that you pass to the controllers.

Have you looked at our MVC sample? That might help to clarify things

https://docs.particular.net/samples/web/send-from-mvc-controller/

As you can see the Application start creates an endpoint and then registers that on the IoC container. The controller declares a dependency on IEndpointInstance or preferably IMessageSession and then calls the method it needs.

I would love to hear some feedback from you in what regards the CoreWebApi sample did not help. With your input, we might be able to optimize the sample to make it simpler to grasp.

Regards
Daniel

Hi Daniel,

Thanks for your reply. Like I said I’am new to NSericeBus and I want to develop a microservice.

The scenario is as follows: I have an MVC application that must talk to aWeb Api and that Web-Api is calling other web Api’s for example a PersonsApi and a CaseMgntApi. The personsApi is responsible for the Personsdata and the CaseMgntApi is responsible for management data, but the CaseMgntApi has also Persondata and I want to Provision persondata data via NServiceBus to the CaseMgntApi to keep it synchronized.
I have tried to implement the mvc example that you mentioned, but it is not working. In the logging I can see that the servicebus is starting (both in the PersonsApi and the CaseMgntApi) but the the CaseMgntApi is not receiving the message.
I hope you understand what I mean. Is there a specific option for web api’s?
Thanks in advance

Kind Regards,
Jacques de Wit

Hi Jacques

Could it be that CaseMgntApi API has on the endpoint configuration object a line that says SendOnly()? Then the endpoint will not receive any messages.

If you want we can hop an a call next week and discuss what you are building as well as troubleshoot what currently is not working. Feel free to send me an email to daniel dot marbach at particular dot net and we can try to find a free slot for next week.

Regards
Daniel

Hi Daniel,

I found the problem. I forgot to derive my message class from the IMessage interface.
It’s working now. Thanks for your help!
Have a nice day,

With kind regards,
Jacques de Wit

Hello Jacques,

Can you please exactly guide us about how have you achieved to communicate two web api’s, one being a sender and another being a consumer?

I am facing the same issue as you were.

Thanks in advance! :slightly_smiling_face:

@sharvi have you tried running the sample mentioned by Daniel? In your scenario do you Send command messages or Publish events?