Giter Club home page Giter Club logo

Comments (4)

squaremo avatar squaremo commented on August 27, 2024

Yeah, I was thinking of that, though I would probably put the optional argument (the topic) second.

from rabbit.js.

squaremo avatar squaremo commented on August 27, 2024

In the amqplib-based implementation, there's no 'topic' option at all yet. There is an undocumented feature whereby you can pass an object to #connect, specifying the exchange name, type and routing key -- but this doesn't really help much if you want to change the topic for each write.

Of course, #write already has a second argument, that is the encoding. So I think this would have to be another method, just for PUB sockets, perhaps #publish(topic, message, [encoding]).

from rabbit.js.

squaremo avatar squaremo commented on August 27, 2024

OK I have implemented #publish as above. There are implications.

One is that it doesn't make much sense unless a SUB socket can subscribe, in some way, to different topics. Here I've followed ZeroMQ, in that subscribing is distinct from connecting:

sub.connect('events');
sub.subscribe('critical.*');

But it's a breaking change, and the semantics are not obvious (do all subscriptions apply to all connections?), and it's all a bit confusing. So I may return to the structured-connection-address mentioned above -- that is, sub.connect({address: 'events', topic: 'critical.*'}) or even sub.connect('events', 'critical.*', callback).

from rabbit.js.

squaremo avatar squaremo commented on August 27, 2024

But it's a breaking change, and the semantics are not obvious (do all subscriptions apply to all
connections?), and it's all a bit confusing. So I may return to the structured-connection-address

Actually, I have added an optional argument to #connect, just for SUB sockets, for the topic. The kind of exchange is determined by the routing option given when creating the socket.

So, in its entirely, it looks like this:

var sub = ctx.socket('SUBSCRIBE', {routing: 'topic'});
var pub = ctx.socket('PUBLISH', {routing: 'topic'}); // must agree on routing if they are to talk
sub.connect('events', 'critical.*'); // the third argument would be a completion callback
pub.connect('events'); // ditto second argument
pub.publish('critical.alarm', "Emergency!", 'utf8');

from rabbit.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.