Neuron ESB User Network

The Service Bus for the Connected Business

The event handler attached to Subscriber.OnReceive() event never fires in WIN FORM application, but works fine in console appliation

Hi,

 

I writing windows form application using Neuron API. I have already setup Topic, Publisher and Subscriber correctly in the "Neuron Esb Explorer" and tested it through test client and it works.
 
On the form's button click event i am connecting to Publisher, Subscriber and sending xml message (<message>Hello world</message>) through publisher to subcriber, I have already wired up an event handler "MyOnReceive" to subscriber.OnReceive event.

 

So following is the code i have done, here the button1_Click() works fine, but the MyOnReceive() event handler never triggers.


        private void button1_Click(object sender, EventArgs e)
        {
            using (Publisher publisher = new Publisher("PublishParam"))
            {
                publisher.Connect();

                // Create an instance of a subscriber.
                using (Subscriber subscriber = new Subscriber("PublishParam"))
                {
                    subscriber.OnReceive += MyOnReceive;
                    subscriber.Connect();

                    // Send an object.
                    publisher.SendXml("PublishParamTopic", "<message>Hello world</message>");

                }
            }
        }

        private/public void MyOnReceive(object sender, MessageEventArgs e)
        {
            ESBMessage message = e.Message;

            string objString = message.GetBody<string>();
            Console.WriteLine(objString.ToString());
        }
       
The strange thing is when i move the above piece of code to console appliation () it works. see the follwoing example. Any idea whats going wrong here?

    public class Program
    {
        static void Main(string[] args)
        {
            using (Publisher publisher = new Publisher("PublishParam"))
            {
                publisher.Connect();

                // Create an instance of a subscriber.
                using (Subscriber subscriber = new Subscriber("PublishParam"))
                {
                    subscriber.OnReceive += MyOnReceive;
                    subscriber.Connect();

                    // Send an object.
                    publisher.SendXml("PublishParamTopic", "<message>Hello world</message>");

                    Console.ReadLine();
                }
            }
        }

        private static void MyOnReceive(object sender, MessageEventArgs e)
        {
            ESBMessage message = e.Message;

            string objString = message.GetBody<string>();
            Console.WriteLine(objString.ToString());
        }
    }

 

Any idea whats going wrong here, I would really appriciate if some one can advise me

 

Views: 299

Reply to This

Replies to This Discussion

notice what you are doing though....for the console app, you have a console.readline() which basically prevents the Subscriber object from going out of scope...hence the event fires.   For the windows app though...you have no stop point...and hence the subscriber goes out of scope and is disposed....hence the event never fires.

What you should do is just create the subscriber as a module level variable so it never goes out of scope.

Kind regards,

Marty Wasznicky
General Manager, Product Field Operations

Neuron ESB

Neudesic, L.L.C.

 

Brilliant! it works! thanks :)

RSS

Neuron ESB Product Support Forums and Communities

Latest Activity

Anupama Nair posted a discussion

Marketo Adapter Invalid Token

Hi,We are using the Marketo adapter to push account updates to Marketo. It works well for some time then starts failing with Invalid Token unless restarted. Is there a configuration that can be done so it can auto refresh the token when required?Thanks!See More
Nov 6, 2023
Sayantini Basak posted a discussion

Maximum payload size(REST API) for requests interfacing to NeuronESB

I am new to Neuron ESB and in our current scenario,We need to process batch transactions comprising of ~1000 records and send them to Neuron ESB for further processing. I would like to understand what is the maximum size of payload that can be transferred using REST interface to Neuron ESB.See More
Jul 22, 2022
Profile IconRobert E Dunie and Sayantini Basak joined Neuron ESB User Network
Apr 28, 2022
Profile IconDayanand, Frederic C, Steffen Greve-Oksfeldt and 1 more joined Neuron ESB User Network
Mar 16, 2022
Profile IconCam Vong and Mitja Luznar joined Neuron ESB User Network
Jan 27, 2022
Profile IconWill Hitzges, Chad Parsons, michael larsen and 4 more joined Neuron ESB User Network
Jun 11, 2021
Anupama Nair posted a discussion

ODBC stored proc polling with temporary tables

We have set up an ODBC adapter to poll a stored proc.We found that if the stored proc has a temporary table defined the rows returned are always 0.Any idea why this would be and what we can do to get around it?See More
Dec 14, 2020
Prasanth Kharade is now a member of Neuron ESB User Network
Dec 30, 2019

Badge

Loading…

© 2024   Created by Neuron Admin.   Powered by

Badges  |  Report an Issue  |  Terms of Service