/*
Copyright 1999-2011 (c) My-Channels
Copyright (c) 2012-2014 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.
Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MyChannels.Nirvana.Samples
{
///
/// This is an example of how to use the .Net extended API for channel / topic subscriptions
///
public class ExChannelSubscriber
{
// the url of the Nirvana realm
private string url;
// the channel to subscribe to
private string channel;
///
/// Pass the rname url of the realm and the channel to subscribe to
///
/// rname of the realm
/// cname name of the channel
public ExChannelSubscriber(string rname, string cname)
{
url = rname;
channel = cname;
start();
}
///
/// Initialise the Session object and set up the Observale query
///
private void start()
{
using (var session = new Session(url))
{
// Initialize the session
session.Initialize();
// Create consumer & subscribe
var consumer = session.Topics.CreateConsumer(channel);
consumer.MessageReceived += (s, e) => ProcessMessage(e.Message);
// Wait for input from the console, exit on key entry
Console.ReadLine();
Console.WriteLine("Exiting the application");
}
}
///
/// Deal with the message
///
/// the Message object received
public void ProcessMessage(Object m)
{
Console.WriteLine("Message :" + ((Message)m).Id);
}
static void Main(string[] args)
{
new ExChannelSubscriber(args[0], args[1]);
}
}
}