RestFul Services

Jul 31, 2012 at 3:55 PM

Does this ESB support REST services. The webservice sample is only SOAP. If it does could someone tell me how its done.

Also my Chat app keeps freezing when its meant to be registering a topic. Do we have any more documentation for this ESB?

Coordinator
Jul 31, 2012 at 4:17 PM
Edited Jul 31, 2012 at 4:19 PM

For documentation you can refer to this link: http://pservicebus.codeplex.com/documentation

You can also refer to this sample which is hosting on my server: http://iomegatrix.com/ChatApp/chat.html to see what you might be missing.

As for your chat app freezing? Did you install the ESB Server first? If you did, then did you install it on the same machine that your  chat app is running from?

If you installed it on a different machine and you trying to access it from a different machine. You will need to open ports to connect to it: 

You can refer to this link for opening the correct ports, the next version automatically do that for you as needed: http://pservicebus.codeplex.com/wikipage?title=Configurating%20Service%20Bus%20to%20run%20on%20Windows%20Server%202008%20RC2&referringTitle=Documentation

 

As for Rest support, Do you mean a Rest transport in which the ESB can make a call to a restful api after receiving a message or do you mean if the ESB server itself is exposed as a restful service?

If your answer is REST transport then yes, there is a REST transport: In form of HttpTransport and BasicHttpTransport. A simple example of what the structure is like is below. The structure can be applied to both HttpTransports, The different between two is that HttpTransports uses QueryParams to Map the message been sent/received to specific querystrings and assumes the method as "POST" and also assume contenttype of application/x-www-form-urlencoded. The BasicHttpTransport allows you to control everything including ContentLength, ContentType, Method, and also include any necessary headers to the request that you may want. But with it the ESB will always simply pass along whatever message was delivered. So in a case where you registered a subscriber that want JSON, you will specific the content-type to json and the method to "POST". Doing will let the ESB convert the published message into json format and invoke your rest service.

 

ESB.With<HttpTransport>(
                transport =>
                {
                    transport.Format = TransportFormat.Xml;
                    transport.QueryParams = new Dictionary<string, string>() { { "to", "To.Value" } };
                    transport.Url = "http://localhost:55196/WebForm1.aspx";
                }).Send(new { To = new { Value = "Olamide" } });


If you answer is Rest API, then you can call the REST API for the ESB manually by pointing to: http://youraddress:8087/ESBRestService. The signature of the rest service can be found here: http://pservicebus.codeplex.com/SourceControl/changeset/view/abcb31765d35#pServiceBus%202.0.0%2fSrc%2fPServiceBus.Web.Rest%2fControllers%2fESBRestServiceController.cs

If you want an easier way to talk to the ESB without having to wrap your head around what method to call, you can also try out the JS API(Better version coming soon in the 2.0.1 version) http://pservicebus.codeplex.com/SourceControl/changeset/view/abcb31765d35#pServiceBus%202.0.0%2fSrc%2fPServiceBus.Services.Web%2fScripts%2fesb.js


Hope the information above is useful, I will try to add it to the wiki.

Let me know if you have any other question. 

Jul 31, 2012 at 5:19 PM

Thank you very much that clears up a few things

Aug 1, 2012 at 3:48 PM

I have another question. From the looks of things, might be one of many.:)

My ESB servers will sit between my clients and a cluster of Servers. All these servers are mirrors of each other and the all expose a Restful service. Now my problem here is how do I make code that can receive a Rest request from my clients, Log the request and the forward that request to one of my servers. Which of the servers?

The esb has to choose which server to route the MSG to using a round robin and active fail over as in if the server is next in the round robin queue but it dies then the ESB should skip to the next server.

Looking at the invoking a webservice example, I am confused as to how I can create a Restful service that listens for my client's rest requests. What is the idea behind subscribers and Topics? Is a topic the method that will deal with the request? Is the subscriber the one that subscribes to a service/Topic?

Coordinator
Aug 1, 2012 at 4:24 PM
Edited Aug 1, 2012 at 4:25 PM
First, Stop looking at the WebService example. The sample only show how you can do a send data to WebService using the ESB API without having to setup all the proxying yourself combined with a WebMethod that eventually Publish a message to the ESB to notify the User that a web method was called.

The ESB is already designed to be clustered. All you need to do is configure it to work that way. You can follow the instruction below to setup it as such.

  • Install the ESB on each of your servers that you want to failover to
  • On each server, stop the PServiceBus.ServiceMonitor(If you don't stop it first, it will restart any service you stop) first then stop every PServiceBus.[servicename]. Also stop all the redis server service instance on them
  • Setup a server, Install MSSQL(if you want to do logging and create a database called servicebus). Pull down this folder from https://hg.codeplex.com/pservicebus/file/abcb31765d35/pServiceBus%202.0.0/Redis%20Server .And run the install.bat file in the Redis Server, doing so will install the Redis Window Service. Then you will need to start it, Look for Redis Service in Windows Services console. You will need to allow connection to the port range: 6379-6384 for redis to accept connections.
  • Then on each server you installed PSB on, go to the installation folder and navigate to the "ESB" folder. Then open the app.config file and every where it says localhost:, replace the localhost with your server ipadress/hostname (where you installed the redis server). You should also open the configurations.xml and do the same, anywhere you see localhost:
  • While you are still in the ESB folder, you should also change the address in the messageStoreConfig/stores/ node in the app.config file
  • On each server go to the ESB installation folder, and navigate to both the "ESB Gateway" and "ESB Router" folders and open the app.config file. In it replace localhost with the server ipaddress/hostname just like you did for the "ESB" folder.
  • Once all that is done, You should start the PServiceBus.ServiceMonitor service on each server and that will start up all your PServiceBus.* services
  • Now your ESB should be ready to failover and also load balance between servers as needed.
For ideas between topic and subscriber you should read the following:
Let me know if that helps :)
Coordinator
Aug 1, 2012 at 4:48 PM

Doing the above will make it possible for you to point to any of your ESB server endpoint and if any fails, it will reconnect to another available server as needed. You will need to do the following also in your application. You can either do it in code using some kinda of factory or something or by config

By doing the following, when the router on one of the server dies, it will look up the next router and try to connect to it

by Code:

ESB.AddRouterAddress("tcp://127.0.0.1:8000");

ESB.AddRouterAddress("tcp://127.0.0.1:8001");

By Config:

 

<configSections>
    <section name="routerConfig" type="PServiceBus.Services.Gateway.Configurations.ESBRouterConfigSection, PServiceBus"/>
  </configSections>
  <routerConfig>
    <routers>
      <add endpoint="tcp://127.0.0.1:8000"/>
     <add endpoint="tcp://127.0.0.1:8001"/>
</routers> </routerConfig>

 

Aug 2, 2012 at 1:42 PM

oK, I have tried a few things. I have to wait for my servers to be ready to do the fail over. however I have been successful in sending a request to my test server. The problem is I cant access the response at all, well I don't know how to.The following code sends a request to a solr server named ghost

                   ESBTransport est =  ESB.With<BasicHttpTransport>
                        (
                            tran =>
                            {
                                tran.Format = TransportFormat.Xml;
                                tran.Url = "http://ghost:8080/SOLR/Parents/select?q=%22Amen%22";
                            }
                        );
                   est.Send(new {});

 

How do i go about accessing the response from my server. Using fiddler it is evident that the request is ok and my server reply properly, I just need the response so I can use it to display stff to my client. Also I noticed that the ESB with the code above sends 2 requests. One with post the other with a GET. Is there a way to stop this because it wastes bandwidth. On ESB MULE you have an option to pick either a post method or a Get.

Coordinator
Aug 2, 2012 at 1:53 PM

The Send method below ignores the response, it is meant only for One Way only. If you want a response, then you should make use of the Pub/Sub system, where you can publish the response as a Topic and have one of your client either on a browser/web app or a window app subscribe to the topic. 

The BasicHttpTransport has a property called Method. It defaults to POST, you can override it.

 ESBTransport est =  ESB.With<BasicHttpTransport>
                        (
                            tran =>
                            {
                                tran.Format = TransportFormat.Xml;

                                 tran.Method = "GET";
                                tran.Url = "http://ghost:8080/SOLR/Parents/select?q=%22Amen%22";
                            }
                        );
                   est.Send(new {}); 

 

The reason you are seeing the first GET is because it test to see if the URL is valid/exists first and if it does it throws an exception. I guess it is kinda of redundant :).

http://pservicebus.codeplex.com/SourceControl/changeset/view/abcb31765d35#pServiceBus%202.0.0%2fSrc%2fPServiceBus.Transports%2fBasicHttpTransport.cs

If you like to remove the logic, you can download from the source, remove the offending code and compile it. This is the code that get called first, which is a GET

if (!Url.Exists()) throw new Exception("Web url does not exist!");

Can you explain to me your goal? so I can provide guidance/help on going forward it with. I think the approach you are taking might not work for you since this would not make any use of the ESB server itself. You are only using the API it provide for quick proxying to your REST service.

Aug 5, 2012 at 6:48 PM
Edited Aug 5, 2012 at 6:50 PM

Basically I am trying to use the service bus to recieve all rest services requests from any client. I will have 2 servers running the service bus. So the service bus will be a sort of middle an between a cluster of solr servers (that are also exposing a restful service) and the clients that are consuming the service.

 

Request

clients ----> ESBs--->CLUSTER

Response

clients<---ESB<---Cluster

 

right now I am just working on just sending a request to the cluster from the esb. At this moment in time I can send to the server and I recieve too but the method I am using to send the request isn't waiting for a reply. Its a one way method. I understand the 'GET' problem i was having. Fixed that too, thanks. So the ESBs will have a service consumer facing the clusters and a service xposer facing the clients, at least thats the basic idea.

Coordinator
Aug 5, 2012 at 7:04 PM

What type of client do you have? Are they running in a browser, window service, window application, mobile? 

I think the best approach no matter what type of client they are is to use a Pub/Sub system not a system where you send request and expect a response from the same pipeline?

Aug 6, 2012 at 3:58 PM

Browser.

I agree and that what I have been trying to implement here using the ESB but im not quite gettin how to implement it. Basically The ESB will be contacted by my clients meaning that the esb must expose some sort of service that will take the URL the user has requested. That url will then be forwarded to the cluster. The cluster will operate on the URL and send back the xml (Rest) to the ESB. the ESB logs the transaction and forwads the reponse to the client.

 

I just cant figure out how to use the pub/sub in this EBS to implement this.

Coordinator
Aug 6, 2012 at 10:28 PM
Edited Aug 6, 2012 at 10:29 PM

Great, It is browser meaning you will be using javascript API. http://pservicebus.codeplex.com/SourceControl/changeset/view/abcb31765d35#pServiceBus%202.0.0%2fSrc%2fPServiceBus.Services.Web%2fScripts%2fpservicebus.pubsub.js

A simple setup such as below will work for what you want to do.

 

  • Create a request topic(ClientRequest) and response topic(ClientResponse)
  • Your client will then need to subscribe to the ClientResponse(With ClientID filter)
  • Create a windows service(on server side), that would subscribe to ClientRequest topic, also setup MessageHandler(OnMessageReceived) to listen for ClientRequest messages
  • When the Handler receive the ClientRequest message in the handler, it should publish a ClientResponse and include the ClientID in the response so that the ESB can route the message to the correct Client as needed.
  • When you Client want an action to be done by the server, your client can simply publish the ClientRequest message and include their clientID and other important information(in your case, a url that point to a resource that the server will process stuff on) that the server would use to generate a response

 

 

Below is the sample code you try to use, Let me know if you need help. Also look at the samples that are provided:

//Register Topics using (Client Side)(Note: You can register the topic from the server side too)
PSERVICEBUS.register({ topic: "ClientRequest", info: { clientID: "", extra: ""} });
PSERVICEBUS.register({ topic: "ClientResponse", info: { clientID: "", extra: ""} });
//Subscribe (Client Logic for subscribe)
PSERVICEBUS.subscribe({
topic: "ClientResponse",
callback: function(msg){
 //DoSomething with response
 }
});
//Subscribe (Server Logic)
var subscriber = Subscriber.New("MyServerSubscriber")
 .SubscribeTo(Topic.Select("ClientRequest"))
 .AddTransport("TransportAlias", Transport.New<TcpTransport>(transport => { }));
subscriber.Save();
subscriber.OnMessageReceived("TransportAlias",
 msg => {
 //Logic to handle request
 });
Aug 7, 2012 at 8:22 AM

This is not a browser application and for security reasons we cant use any java script. Would have a c# version of your sample code above. I like the break down you have done there. I suspect that will be the same procedure even in the c# solution.

Coordinator
Aug 7, 2012 at 1:19 PM
Edited Aug 7, 2012 at 1:19 PM

You are correct, the same logic can be used from the C# client API too.

Aug 7, 2012 at 2:27 PM

System.TypeInitializationException was unhandled by user code
  Message=The type initializer for 'PServiceBus.Services.Gateway.Runtime.ESB' threw an exception.
 

I am getting the error above when i try to configure ESB with address. below is the code I am using

.
.
        public Service1()
        {
            ESB.Authenticate("rpgmaker", "password1");
            ESB.ConfigWithAddress("tcp://127.0.0.1:8000");
            Topic.Register<UrlRecieveComplete>();
        }
.
.

Coordinator
Aug 7, 2012 at 2:34 PM

Have you installed the ESB on your machine? Can you paste the full stack trace here?

Aug 7, 2012 at 2:37 PM

ESB if fully installed and working with the examples yes

 

System.TypeInitializationException was unhandled by user code
  Message=The type initializer for 'PServiceBus.Services.Gateway.Runtime.ESB' threw an exception.
  Source=PServiceBus
  TypeName=PServiceBus.Services.Gateway.Runtime.ESB
  StackTrace:
       at PServiceBus.Services.Gateway.Runtime.ESB.Authenticate(String username, String password)
       at REST_TEST.Service1..ctor() in c:\users\tmunyu\documents\visual studio 2010\Projects\REST_TEST\REST_TEST\Service1.svc.cs:line 20
       at CreateREST_TEST.Service1()
       at System.ServiceModel.Dispatcher.InstanceProvider.GetInstance(InstanceContext instanceContext, Message message)
       at System.ServiceModel.Dispatcher.InstanceBehavior.GetInstance(InstanceContext instanceContext, Message request)
       at System.ServiceModel.InstanceContext.GetServiceInstance(Message message)
       at System.ServiceModel.Dispatcher.InstanceBehavior.EnsureServiceInstance(MessageRpc& rpc)
       at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
       at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
       at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
       at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
       at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
       at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
       at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
       at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)
  InnerException: System.NullReferenceException
       Message=Object reference not set to an instance of an object.
       Source=PServiceBus
       StackTrace:
            at PServiceBus.Core.Runtime.Configuration.ConfigurationFactory.GetConfigSection[TConfigSection]()
            at PServiceBus.Services.Gateway.Runtime.ESB..cctor()
       InnerException:

Coordinator
Aug 7, 2012 at 2:50 PM

I see the problem now. It is failing at GetConfigSection for ESBRouterConfiguration. I have used it from a WCF service and never had any error message before. Can you paste your app.config file for your WCF service here for me to view?

The problem is coming from this logic here(which i think should not be a problem because i tried it before with WCF and it worked fine)

http://pservicebus.codeplex.com/SourceControl/changeset/view/abcb31765d35#pServiceBus%202.0.0%2fSrc%2fPServiceBus.Core%2fRuntime%2fConfiguration%2fConfigurationFactory.cs

 var ex = MethodHelper.Try(() => configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));
            if (ex != null)
                configuration = System.Web.Configuration.WebConfigurationManager
                    .OpenWebConfiguration(System.Web.HttpContext.Current.Request.Path);

 

Aug 7, 2012 at 3:03 PM

<?xml version="1.0"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

 

This is the only app.config in my project

Aug 7, 2012 at 3:05 PM

The problem occurs even with my class libraries.

Coordinator
Aug 7, 2012 at 3:19 PM
Edited Aug 7, 2012 at 3:21 PM

I cannot reproduce the problem. But you can use the temporary fix.

Let me know if it resolved your problem

http://pservicebus.codeplex.com/SourceControl/changeset/e2f6a35c1e5e

Sorry, you will need to compile the source again using the build.cmd :)

Aug 7, 2012 at 4:15 PM

Thanks I will try that

Aug 8, 2012 at 1:44 PM

I finally have something. when i rebuilt the esb with eh changes you suggested, the esb services for WCF, Logging and Gateway stopped working. they wouldn't start. So I have decided no to use WCF and use ASP instead. The ASP is working with the original 2.0.0 binaries. So now I can receive from my clients, forward to my cluster, wait for reply and forward reply to client. I achieved this by adding a costume send method to a class that implement BasicaHttpTransport. This works but bypasses the publish subscribe architecture. I just couldn't get that to work at all. There is still lots more to do but thank you for the help so far   

Coordinator
Aug 8, 2012 at 2:03 PM

I see, I remove the code for checking if there is an exception and simply check for null configuration. Could you try that also to see if it works for you?

Great that it is working for you now, but I still think the Pub/Sub way would be better in the long run. I will try to make a sample, that demonstrate using the Pub/Sub for what you are trying to do when I have a chance.

Aug 23, 2012 at 1:12 PM

Hi its been a while. We have been using the ESB and so far the testing has gone very well

We are moving on the the next stage now of implementing the failover on the ESB servers. Now the failover part it fairly easy to setup as explained on the following wiki

http://pservicebus.codeplex.com/wikipage?title=How%20to%20setup%20the%20ESB%20as%20a%20cluster%20for%20fail-over&referringTitle=Documentation

 

However, say I was using 2 ESB servers. How do you insure that if one server goes down my clients (anyone with a webbrowser) still get a reply. What I mean is do these esbs share an IP address therefore both receive the client msg and only one replys to the msg. If so how do you setup the round-robin so they can take turns to process

Coordinator
Aug 24, 2012 at 12:59 AM

Since i am not 100% sure how you are using the ESB. I will assume you are using Topic.Publish/PublishMany method for sending messages and you have some subscriber subscribing to it.

If you follow this model, then based on the wiki post above you would configure your clients application to register the two esb server router component either by code or config. And the ESB would also route message between the gateways running on both your ESB Servers. And in a situation where one of the gateway dies, it will automatically connect to the next available gateway on the server that is still available. 

But if you are using the ESB.With<Transport>().Send method, you are not really using the ESB server. You are just making use of the API provided to do a direct communication to your transports/endpoints. This process does not take advantage of any of the routing/load distribution capability of the ESB.

Aug 29, 2012 at 11:41 AM

I have decided to give the Publish/subscribe another stab. I am running into a bit of a problem. I have 3 applications, one for the MVC client app the other is a test receiver and the ESB. In the application method of the MVCI have registered the ESB like this

                                                                                                   new ESBPrep("HomeController");

the ESBPrep method Registers the fail over serves, The topic and the Subscribers. The problem is this works a few time and then it stops again.  I have tried to fix this but I an out of ideas now

Coordinator
Aug 29, 2012 at 1:58 PM

If you are going with the pub/sub method. You would not want to do a subscriber in your MVC using the .NET Client API, you would want to set it up with the JS Client API. The reason you are having problem is most likely because your page finished loading and killed the thread that is suppose to receive the message. 

 

You should try to follow what i described previously. Try to get a sample working with the flow below

 

Great, It is browser meaning you will be using javascript API. http://pservicebus.codeplex.com/SourceControl/changeset/view/abcb31765d35#pServiceBus%202.0.0%2fSrc%2fPServiceBus.Services.Web%2fScripts%2fpservicebus.pubsub.js

A simple setup such as below will work for what you want to do. And if it is possible, may I see your current code that is not working? Maybe I can help you in making it work

 

  • Create a request topic(ClientRequest) and response topic(ClientResponse)
  • Your client will then need to subscribe to the ClientResponse(With ClientID filter)
  • Create a windows service(on server side), that would subscribe to ClientRequest topic, also setup MessageHandler(OnMessageReceived) to listen for ClientRequest messages
  • When the Handler receive the ClientRequest message in the handler, it should publish a ClientResponse and include the ClientID in the response so that the ESB can route the message to the correct Client as needed.
  • When you Client want an action to be done by the server, your client can simply publish the ClientRequest message and include their clientID and other important information(in your case, a url that point to a resource that the server will process stuff on) that the server would use to generate a response

 

 

Below is the sample code you try to use, Let me know if you need help. Also look at the samples that are provided: 

//Register Topics using (Client Side)(Note: You can register the topic from the server side too)
PSERVICEBUS.register({ topic: "ClientRequest", info: { clientID: "", extra: ""} });
PSERVICEBUS.register({ topic: "ClientResponse", info: { clientID: "", extra: ""} });
//Subscribe (Client Logic for subscribe)
PSERVICEBUS.subscribe({
topic: "ClientResponse",
callback: function(msg){
 //DoSomething with response
 }
});
//Subscribe (Server Logic)
var subscriber = Subscriber.New("MyServerSubscriber")
 .SubscribeTo(Topic.Select("ClientRequest"))
 .AddTransport("TransportAlias", Transport.New<TcpTransport>(transport => { }));
subscriber.Save();
subscriber.OnMessageReceived("TransportAlias",
 msg => {
 //Logic to handle request
 });

 



 

Aug 30, 2012 at 11:28 AM

As i mentioned before, we are trying to avoid JavaScript by all means. We want a pure .net solution for the ESB.

At the moment I have a mvc applicatioin and a class library that holds all the logic for the ESB ie Registering and subscribing. In the class library I have two classes:

---------msgDock.cs--------

// This is my topic

public class MsgDock
    {
        public string Publisher { get; set; }
        public string Message { get; set; }

        public static MsgDock New(string publisher, string message)
        {
            return new MsgDock {Publisher = publisher, Message = message};
        }
    }

--------ESBPrep----------

//this is for the preparing the ESB

    public class ESBPrep
    {

        public ESBPrep(String name)
        {
            ESB.Authenticate("rpgmaker", "password1");
            ESB.ConfigWithAddress("tcp://127.0.0.1:8000");
            RegisterTopic();
            Subscribe(name);
        }

        public static void SendMessage( string publisher,string message)
        {
            Topic.PublishMessage(MsgDock.New(publisher, message));
        }

        static void RegisterTopic()
        {
            if (Topic.Exists<MsgDock>()) return;
            Topic.Register<MsgDock>();
        }

        public static void Subscribe(string publisher)
        {

            var port = Process.GetCurrentProcess().Id;

            var subscriber = Subscriber.New("rrr").Durable(false)
                .SubscribeTo(Topic.Select<MsgDock>())
                .AddTransport("Tcp", Transport.New<TcpTransport>(
                    transport =>
                        {
                            transport.Format = TransportFormat.Json; transport.IPAddress = "127.0.0.1";
                            transport.Port = port;
                        }), "MsgDock")
                ;

            subscriber.Save();

            subscriber.OnMessageReceived<MsgDock>("Tcp", HandleMessage,
                                                  interval: TimeSpan.FromMilliseconds(1),
                                                  errorAction: h =>
                                                                   {
                                                                       h.Continue = true;
                                                                       Console.WriteLine(h.Error.ToString());
                                                                   });
        }


        private static void HandleMessage(MsgDock msg)
        {
            MessageBox.Show(msg.Message);
            if (msg.Message == null) return;
            Console.WriteLine("{0}: {1}\n", msg.Publisher, msg.Message);
        }
    }

I make a new object of the ESBPrep at the start of my MVC. In the Globall.asax file. Then in the MVC application I have a HomeController that recieves from my Clients Application which is also an MVC application(This is the one that keeps track of its users IDs. The ESB will send a msg back to this app and it will deal with sending back to the user)

 

-------HomeController.cs---------

    public class HomeController : Controller
    {
        public ActionResult DoIt()
        {
            if (HttpContext.Request.Url != null)
                if (HttpContext != null)
                {
                    ESBPrep.SendMessage("rrr", HttpContext.Request.Url.AbsoluteUri);
                }
            return View();
        }
    }

I have tried dynamic names to register to the topic with no luck

Coordinator
Aug 30, 2012 at 1:45 PM
First thing to note. You realise that MessageBox.Show and Console.WriteLine does not work in a web context.

And secondly, I would suggest doing the DoIt method like the below instead

public ActionResult DoIt(){
if(HttpContext != null){
var request = HttContext.Request;
if(request != null) {
ESBPrep.SendMessage("rrr", request.Url.AbsoluteUri);
}
}
}

The other problem is see is with your subscriber logic, you are using Process.GetCurrentProcess().Id, which will return the same ID all the time any MVC app you launch since the process is the asp.net worker process

I would suggest not using TcpTransport also since this application is running from inside of your MVC app.

And even if you decide to keep the TcpTransport, your OnMessageReceived HandleMessage would not since it is not running within your page itself, but rather on your asp.net worker process.
This would mean that you cannot correlate the message received to your client since the request/response are stateless and do not wait for your OnMessageReceive to be executed to have the scope as your MVC app would.

In conclusion, creating the subscriber object from MVC is fine. But listening to the message published by HomeController#DoIt method within your MVC would never work since your OnMessageReceived is really just running in the asp.net worker process and you cannot connect to original http request/response that issue the listening logic(OnMessageReceived)

I understand that you are trying to avoid using Javascript for any of this stuff. But at the end of the day, your MVC would only be good for publishing/registering topic messages, and creating a subscriber to subscribe to the topic. It would not be able to invoke onMessageReceived properly without a lot of hacks due to the way http request/response works. There are many other library out there too with the same limitation such as SignalR, NServiceBus and e.t.c

And better solution would be to let your MVC application do the publishing of the message, and creating a subscribe object for the ESB. But let the javascript listen for the message so that it can be unique to each of your connected clients.

I can create a sample, If you want me to show using MVC app to send message using the C# client and receive it in other MVC app using javascript client