Develop the C# client for sending and receiving messages through Solace Broker

sreeramgp Member Posts: 4
edited April 2022 in PubSub+ Event Broker #1

Hi Team,

I am new to Solace Pubsub broker. This is my first posting. So please apology me, if my query is not clear. I can elaborate it, if it requires.

We want to develop the POC to send and receive messages (Pubsub pattern) for C# (Client).

  1. How to pass a data/messages using event schema defined in the event?
  2. How to retrieve data/messages (Subscribe)?
  3. How to generate automatic code using Async API for C#?

We need the sample code snippet using C#. Could you please help us any useful links.

Note: These code samples are helpful by passing data using Schema. I mean, more real time samples rather Hello World!!! ones. These samples are not using Event schema for passing the data.






  • Aaron
    Aaron Member, Administrator, Moderator, Employee Posts: 483 admin

    Hi @sreeramgp , welcome to the Community!

    Solace doesn't have an "out of the box" schema validator, mostly because Solace is a pub/sub event broker, not a streaming database... although there can be a lot of similar functionality between the two types of platforms. Knowing the payload format/schema is business logic that the application must implement. For example, when I write a subscriber, I know based on the topic that I received the message on how to parse its payload.

    Our C# samples are here: And you can download the C# API from our downloads page:

    If you prefer to not rely on the topic for determining how to parse your payload, there are other fields in the message metadata that could be used. For example, I'd recommend "Application Message Type", which is a string. It is compatible with JMS MessageType, in case you need interoperability with Java apps. In some lower-latency use cases, where the message is not self-describing, this field can point to a schema dictionary lookup that the app can use to figure out how to parse the message.

    Hope that helps!

  • sreeramgp
    sreeramgp Member Posts: 4

    Thanks Aaron for detailed information. I have been watching your Videos and Blog’s. It is more informative.

    I am new to Solace. So please excuse me, if I miss/wrongly quoted.

    I got your point. Here I am placing my understanding.

     Application is associated with events (Pub/Sub Events). Events are associated with Topic and Schema.

    From Publisher angle, Based on business logic he generates the Payload in accordance with Schema. Below is the sample code.

    string Payload = string.Empty();

    //After process the business logic, It returns the PayLoad according to Schema associated with Topic

    Payload = ProcessMyBusinessLogic(); //Here business logics varies from case to case

    // Generated sample Payload

    Payload = {

       "productId": 1,

       "productName": "An ice sculpture",

       "price": 12.50,

       "tags": [ "cold", "ice" ],

       "dimensions": {

         "length": 7.0,

         "width": 12.0,

         "height": 9.5


       "warehouseLocation": {

         "latitude": -78.75,

         "longitude": 20.4



    // Ignoring the rest of the Solace framework objects for creating Context, Sessions and Message

    Publishing Message

    message.Destination = ContextFactory.Instance.CreateTopic("tutorial/product");

    // Create the message content as a binary attachment

    message.BinaryAttachment = Encoding.ASCII.GetBytes(Payload);

    // Publish the message to the topic on the Solace messaging router

    Console.WriteLine("Publishing message...");

    ReturnCode returnCode = session.Send(message);

     From Consumer side (Subscriber)

    Session.Subscribe(ContextFactory.Instance.CreateTopic("tutorial/product "), true);

    //Handler look for subscribed messages

           private void HandleMessage(object source, MessageEventArgs args)


               Console.WriteLine("Received published message.");

               // Received a message

               using (IMessage message = args.Message)


                   // Expecting the message content as a binary attachment

                   Console.WriteLine("Message content: {0}", Encoding.ASCII.GetString(message.BinaryAttachment));

                   // finish the program




    Please correct me if my understanding is wrong😗

     Also, I am not clear on Application Message Type if we are not relay on Topic. Could you please share useful links for this.

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 848 admin

    Hi @sreeramgp,

    I'll continue where @Aaron left off. I only have a few minutes so I'll do a TLDR response.

    The Solace Event Broker doesn't do payload validation of events as it doesn't look at an event's payload at all. Therefore it is a responsibility of the application to do so.

    Aaron was saying that you can either do this by looking at the topic a message was published on, for example a msg sent to "tutorial/product" might be expected to have a payload which complies with a "Product" schema. Otherwise, if you don't want to rely on the topic for this then you could have the product put metadata in the message headers (or user properties) that allow consumers to know how to parse the payload on the other side. One common way of doing that is by using the ApplicationMessageType header.

    Docs for the header is here.