Skip to content

Wildcards in routingkeys #22

@shurik239

Description

@shurik239

I have still the huge problem using wildcards in routing keys.
What I want to archive:
I have two subscribers:
First one should listen all events in exchange.
Second one should listen only event with specific routing key.

Example implementation you can find below.

If I omit messageType on Publisher - both subscribers are called twice.
If i set messageType to "#" - only second subscriber will be called, but again twice.

I know about issue using messageTypes, but have no idea how can I avoid this with some workaround.

var util = require("util");
var Rabbus = require("rabbus");
var wascally = require("wascally");

wascally.configure({
    "connection": {
        "server": "localhost",
        "vhost": "/",
        "user": "guest",
        "pass": "guest"
    },
    "consumerId": "test"
}).then(function () {

    var c1 = new Rabbus.Subscriber(wascally, {
        exchange: {
            name: 'pub-sub.exchange',
            type: 'topic'
        },
        routingKey: "pub-sub.key",
        queue: "foo1"
    });

    c1.subscribe(function(msg, props, actions){
        console.log("c1 got it!");
        actions.ack();
    });

    var c2 = new Rabbus.Subscriber(wascally, {
        exchange: {
            name: 'pub-sub.exchange',
            type: 'topic'
        },
        routingKey: "#",
        queue: "foo2"
    });

    c2.subscribe(function(msg, props, actions){
        console.log("c2 got it!");
        actions.ack();
    });

    setTimeout(function () {
        function SomePublisher(){
            Rabbus.Publisher.call(this, wascally, {
                exchange: {
                    name: 'pub-sub.exchange',
                    type: 'topic'
                },
                routingKey: "pub-sub.key",
                messageType: "#"
            });
        }

        util.inherits(SomePublisher, Rabbus.Publisher);
        var publisher = new SomePublisher();

        var message = {
            place: "world"
        };

        publisher.publish(message, function(){
            console.log("published a message");
        });
    }, 250);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions