public void testPublish() { var listener = new TestListener(); new QTopic(TOPIC_NAME).register(FieldsReceiver.receiver(listener)); IDictionary <string, object> message = new Dictionary <string, object> { { "foo", 123.45 } }; var topic = new Topic(TOPIC_NAME); topic.send(message); Objects.sleep(100); AreEqual(123.45, listener.received.numeric("foo")); topic.send("bar", "string initializedValue"); Objects.sleep(100); AreEqual("string initializedValue", listener.received.get("bar")); var data = new string[3, 2]; data[0, 0] = "key1"; data[0, 1] = "value1"; data[1, 0] = "key2"; data[1, 1] = "value2"; data[2, 0] = "key3"; data[2, 1] = "value3"; topic.send(data); Objects.sleep(100); AreEqual("value1", listener.received.get("key1")); AreEqual("value2", listener.received.get("key2")); AreEqual("value3", listener.received.get("key3")); }
public void subscribeIfNeeded() { lock (listeners) { if (listeners.ContainsKey(this)) { return; } var listener = new TopicListener(this); listeners[this] = listener; jTopic.register(FieldsReceiver.receiver(listener)); } }
public static MessageReceiver receiver(Action <Fields> action) { return(FieldsReceiver.receiver(new ActionListener(action))); }
public void subscribe(Action <Fields> onFields) { jTopic.register(FieldsReceiver.receiver(new ActionListener(onFields))); }
public void initialize() { rediTopic.register(FieldsReceiver.receiver(new Channel.ActionListener(updatePositions))); aimTopic.register(FieldsReceiver.receiver(new Channel.ActionListener(updatePositions))); }
public PublishCounter(Topic topic) { this.topic = topic; topic.jChannel().register(FieldsReceiver.receiver(this)); topic.subscribeIfNeeded(); }