[zeromq-dev] xpub and xsub example
Mohit Jaggi
mohitjaggi at gmail.com
Wed Jan 16 00:51:49 CET 2013
That seems to have worked(except that publisher should be on heap not
stack)...worth adding to the C++ example in the guide?
On Mon, Jan 14, 2013 at 10:50 PM, Mohit Jaggi <mohitjaggi at gmail.com> wrote:
> Thanks....Based on Figure 13 in the guide, I guess I would do the
> following:
>
> static void *pubsub_proxy_thread(void *arg){
> zmq_proxy(g_xsub, g_xpub, NULL);
> }
>
> int global_init() {
> pthread_t t;
>
> try {
> ...
>
> g_xpub.bind("tcp://*:7779"); //subscribers connect here
> g_xsub.bind("inproc://xsub_sock"); //publishers connect here
>
> assert(0 == pthread_create(&t, NULL, nbapi_pubsub_proxy_thread, NULL));
> }
> catch(const exception& e) {
> cerr << "Exception: " << e.what() << endl;
> return -1;
> }
> return 0;
> }
>
> /*
> *
> */
> __thread *tls_publisher;
> int thread_init() {
> try {
> socket_t publisher(g_ctx, ZMQ_PUB);
> publisher.connect("inproc://xsub_sock");
> tls_publisher = &publisher; //every thread uses this in thread local
> storage to publish messages
> }
> catch(const exception& e) {
> cerr << "Exception: " << e.what() << endl;
> return -1;
> }
> return 0;
> }
>
>
> On Mon, Jan 14, 2013 at 2:55 PM, Pieter Hintjens <ph at imatix.com> wrote:
>
>> From https://github.com/imatix/zguide/blob/master/examples/C/lvcache.c:
>>
>> int main (void)
>> {
>> zctx_t *context = zctx_new ();
>> void *frontend = zsocket_new (context, ZMQ_SUB);
>> zsocket_bind (frontend, "tcp://*:5557");
>> void *backend = zsocket_new (context, ZMQ_XPUB);
>> zsocket_bind (backend, "tcp://*:5558");
>>
>>
>>
>>
>> On Mon, Jan 14, 2013 at 11:39 PM, Mohit Jaggi <mohitjaggi at gmail.com>
>> wrote:
>> > Thanks Charles(new to IRC, thanks for the advice!) and Peter. The
>> example
>> > you pointed out does use XPUB/XSUB. Am I missing something?
>> >
>> >
>> > On Mon, Jan 14, 2013 at 2:25 PM, Charles Remes <lists at chuckremes.com>
>> wrote:
>> >>
>> >> On Jan 14, 2013, at 4:10 PM, Mohit Jaggi <mohitjaggi at gmail.com> wrote:
>> >>
>> >> Hi All,
>> >> I am looking for examples of xpub and xsub. My use case is that
>> multiple
>> >> threads in a process produce data that needs to be published over a TCP
>> >> socket. I was thinking of letting them call "send" but it seems that
>> that is
>> >> not thread-safe. From the guide, it appears I can use inproc+xpub
>> socket
>> >> from producers to a proxy and let subscribers connect over TCP/xsub.
>> >> However, there is no example code.
>> >>
>> >>
>> >> I answered your question on irc. When asking a question, you should
>> stick
>> >> around for more than 5m to get an answer.
>> >>
>> >> Create a forwarder device that all of your PUB sockets connect to. All
>> SUB
>> >> sockets should then subscribe to that forwarder. You do *not* need to
>> mess
>> >> with XPUB and XSUB sockets.
>> >>
>> >> See here:
>> >>
>> >> http://api.zeromq.org/3-2:zmq-proxy
>> >>
>> >> and
>> >>
>> >> http://zguide.zeromq.org/page:all#Intermediaries-and-Proxies
>> >>
>> >> cr
>> >>
>> >>
>> >> _______________________________________________
>> >> zeromq-dev mailing list
>> >> zeromq-dev at lists.zeromq.org
>> >> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>> >>
>> >
>> >
>> > _______________________________________________
>> > zeromq-dev mailing list
>> > zeromq-dev at lists.zeromq.org
>> > http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>> >
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev at lists.zeromq.org
>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20130115/bb53e616/attachment.htm>
More information about the zeromq-dev
mailing list