Skip to content

Add NginxPubSubTopic(Java)/PubSubTopic(Clojure) to simplify handling messages among Nginx worker processes #97

Closed
@xfeep

Description

@xfeep

Because broadcast API is a little too low level to use simply, we need provide NginxPubSubTopic(Java)/PubSubTopic(Clojure) to simplify handling messages among Nginx worker processes.

For Clojure

(defn build-topic! [name]
  "build a topic" 
.........)

(defprotocol PubSubTopic
  (pub! [topic message]
     "Publishs a message to the topic")
  (sub! [topic att callback]
     "Subscribes to a topic and returns an unsubscribing function. 
When a message comes the callback function will be invoked. e.g.
      (def my-topic (build-topic! \"my-topic\"))
      (sub! my-topic (atomic 0) 
           (function [message counter]
              (println \"received :\" message \", times=\" (swap counter inc)))")
  (destory! [topic]
      "Destory the topic."))

For Java

public class NginxPubSubTopic {

    public NginxPubSubTopic(String topic);

    public void pubish(String message);

    public <T> PubSubListenerData<T> subscribe(T data, NginxPubSubListener<T> listener);

    public void unsubscribe(PubSubListenerData pd);

    public void destory();
}

In nginx.conf

##define a shared map for PubSubTopic
shared_map PubSubTopic tinymap?space=1m&entries=256;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions