Publisher' has to be a class implementing bbv.Common.EventBroker.IHandler.

45 views
Skip to first unread message

bob.g....@googlemail.com

unread,
Apr 6, 2012, 11:36:27 AM4/6/12
to bbvc...@googlegroups.com

   Ive started using the bbv.Common.EventBroker. Again a real cool bit of code. Real handy to bubble up events from below to the UI.

   I'm following the basic tutorial.  My publisher is

   public class Publisher
    {
        [EventPublication(EventTopics.HBMissedEvent)]
        public event EventHandler HBMissedEvent;

        ///<summary>Fires the SimpleEvent</summary>
        public void CallHBMissedEvent()
        {
            HBMissedEvent(this, EventArgs.Empty);
        }
    }

with my scubscriber is

  public class Subscriber
    {
        [EventSubscription(
            EventTopics.HBMissedEvent,
            typeof(Zeta.Events.Publisher))]
        public void HBMissedEvent(object sender, EventArgs e)
        {
            Console.WriteLine("Heartbeat missed");
        }

    }

with a very basic EventBroker setup as follows:

            Broker = new EventBroker();
            Pub = new Publisher();
            Broker.Register(Pub);

            Sub = new Subscriber();
            Broker.Register(Sub);
            Pub.CallHBMissedEvent();

but get an exception of {"handlerType 'Zeta.Events.Publisher' has to be a class implementing bbv.Common.EventBroker.IHandler."} . Perhaps something to do with the attribute definiton, on subscriber.  Do I need to implement IHander on the publisher. Simple docs don't detail, nor does any of the tests seem to implement IHandler, for simple scenario like this.

Thanks,
Bob.

 

Urs Enzler

unread,
Apr 6, 2012, 1:27:15 PM4/6/12
to bbvc...@googlegroups.com
Hi Bob

That's a common pit fall and therefore we'll make some changes in the next version.

Change your subscriber to:

  public class Subscriber
    {
        [EventSubscription(
            EventTopics.HBMissedEvent,
            typeof(EventBroker.Handlers.Publisher))]

        public void HBMissedEvent(object sender, EventArgs e)
        {
            Console.WriteLine("Heartbeat missed");
        }

    }

Note that I changed the type in the EventSubscription. This is not the type of your publisher. This is a type specifying how the event is handled and Publisher means that the event is handled synchronously on the same thread as the event is fired.

See also http://www.appccelerate.com/eventbroker.html for a better documentation than on the bbv.Common site.

We will soon release the first version of Appccelerate (which is just the next version of bbv.Common), but you can already get a pre-release over Nuget - just search for Appccelerate with the pre-release option enabled.

Cheers
Urs

Reply all
Reply to author
Forward
0 new messages