Archived

This forum has been archived. Please start a new discussion on GitHub.

Publish/Subscribe strategy

My task is to create a publisher(server) which can publish hundreds of items. Each item may be of a type which is in a set of types, like date, number, string, yield curve or matrix of any heterogeneous collection of types.
I've successfully coerced the IceStorm.Counter example to publish and subscribe these types using the following slice definition.

class Value
{
string Serialise();
};

class ValueDate extends Value
{
double mDate;
};

class ValueString extends Value
{
string mString;
};

class ValueNumber extends Value
{
double mNumber;
};

sequence<Value> ValueVec;

class ValueMatrix extends Value
{
int mCols;
int mRows;

ValueVec mValueVec;
};

class ValueCurve extends Value
{
ValueVec mDates;
ValueVec mValues;
};




interface ValueObserver
{
void SetValue(Value value1);
};

interface ValueRecord
{
void subscribe(ValueObserver* observer);
void unsubscribe(ValueObserver* observer);

void SetValue(Value value1);
};

Whatever type the publisher decides to publish, successfully arrives at all subscribers due to the type inheritance described in the slice definition above.

Now for the problem I'm having difficulty with.
The example above has one item published via IceStorm and the clients subscribe to this one item.
I wish to publish hundreds of named items and the publisher needs to be able to publish and remove named items on the fly, without prior knowledge of these items.
The client needs to be able to subscribe and unsubscribe to any number of the published items by name, e.g. newItem->Subscribe("USD_YieldCurve3Month");

I've looked at all of the sample programs but still can't work out a working strategy, let alone a best strategy.
I'm not sure if each published item should be an individual topic and IceStorm can be used to manage the publish/subscribe details or whether a single ICE object should contain a collection of published items and manage the publish/subscribe details.

Do you have any architectural advice or advice on how to publish many named items for a client to selectively subscribe to.

Comments

  • benoit
    benoit Rennes, France
    Hi Gordon,

    The best option right now is to have one IceStorm topic per item and provide some interface to your client and your publisher that enables them to subscribe/unsubscribe and publish. For example:
    class Value
    {
         string name; // The ID of the value.
    };
    
    interface ValueObserver
    {
        void SetValue(Value value1);
    };
    
    interface ValueRecord
    {
        void subscribe(Ice::StringSeq names, ValueObserver* observer);
        void unsubscribe(Ice::StringSeq names, ValueObserver* observer);
    
        void publish(Value value1);
    };
    

    Under the hood, the implementation of the ValueRecord interface would create one IceStorm topic per value name. The implementation of publish would lookup the topic for the value name and publish the value on the topic publisher. The implementation of the subscribe/unsubscribe methods would subscribe or unsubscribe the given observer to each of the topics for the given value names.

    Note that we are considering making some improvements for IceStorm that would better suit this use-case. So don't hesitate to provide more feedback on your needs and your application if there are features that you would like to have in IceStorm that don't exist right now (you can also contact us directly at info@zeroc.com if you prefer).

    With the interfaces suggested above, you hide from the publisher and subscriber the messaging service that is running behind the ValueRecord interface, you could therefore make some improvements to its implementation in the future without affecting the subscribers/publishers.

    Cheers,
    Benoit.
  • Thanks Benoit, for your prompt reply.

    I followed your advice, which was easy to follow, and have got my prototype working as expected.

    cheers
    Gordon