Skip to content

uvatmvf/EasyWcfPubSub

Repository files navigation

Easy Wcf PubSub Service and Client

A publisher subscriber service implemented in C#/WCF

Simple asynchronous pub sub service implemented in .Net WCF.

Why?

NOTE: WCF is deprecated. Use gRPC instead.

Many pub-sub implementations couple publishers and subscribers using a static event callback. This can cause delays when serving publications to slow clients. These do not scale, and fail on intermittency or clients that take a long time to process/accept the subscription.

This implementation decouples publishers and subscribers into asynchronous, fire and forget callbacks.

Most pub-sub implementations are library implementations.

This implementation publishes through a WCF service, using a generic interface.

Most wcf services require the clients to adopt the typed library of the service contract.

The publisher and subscribers are free to serialize objects through the pipe with no changes to the data contract by allowing them to serialize to JSON/Xml/whatever before serializing publish and deserializing after subscription is received.

At a glance

  • Wcf Pub Sub Service
  • Wcf Pub Sub Console Application
  • Wcf Pub Sub Publish-Subscriber Interface library
  • Wpf Sample Application

Getting Started with the Pub Sub Service

  • To Publish:

    {        
        var publisher = new PublisherBase();    
        publisher.Publish("channel", "foo");
    }
    
  • To Subscribe:

    {
        
        var subscriber = new SubscriberBase(new string[] { "channel1", ... })
        // if you want to subscribe to all channels, pass empty or null string array for channels to constructor.
        {
           Publish = (channel, publication) => { 
              Console.WriteLine($"Listening on {Channel} to receive {publication}");              
              }
          },                                                      
          //  syncContext = SynchronizationContext.Current, // uncomment if you want to set a synchronization context
        }       
                
        // SubscriberBase.AsyncPublications = false; // uncomment if you want to handle all subscriptions synchronously
        
        // SubscriberBase.UseSyncContext = true; // uncomment if you want to use the synchronoization context 
        
    }
    

Nuget

Install-Package Easy.Wcf.PubSub.Client -Version 1.0.0

Install-Package Easy.Wcf.PubSub.Server -Version 1.0.0

Quick Start Examples

1. Download code from repository.
  1. Open solution file. (Restore nuget packages)

  2. Build all.

  3. Open WcfPubSubConsoleServer bin\debug folder

  4. Run WcfPubSubConsoleServer.exe as administrator

  5. Open WcfSampleClient bin\debug folder

  6. Run TestPubSub.exe application.

The console server should look like:

server:

client:

The sample client and server applications provide demonstration for the pub sub service. The sample application has a proxy class generated from the WCF service and configuration files. All publications are serialized to string (JSON, XML) before publishing to the service. The sample application demonstrates two types of message publication, string and jpeg image. (And you can define any data you want).

TODO: Reimplement POC in gRPC repo.