diff --git a/README.md b/README.md index 5d3fc8c..b5005c8 100644 --- a/README.md +++ b/README.md @@ -93,10 +93,10 @@ dupSubscription.unsubscribe(); ## How can I extend it? There are two main ways you can extend Postal: -* First, you can write an entirely new bus implementation (want to tie into a real broker like AMQP, and wrap it with Postal's API? This is how you'd do it.). If you want to do this, look over the `localBus` implementation to see how the core version works. Then, you can simply swap the bus implementation out by calling: `postal.configuration.bus = myWayBetterBusImplementation`. +* First, you can write an entirely new bus implementation (want to tie into a real broker like RabbitMQ by hitting the [experimental] JSON RPC endpoints and wrap it with Postal's API? This is how you'd do it.). If you want to do this, look over the `localBus` implementation to see how the core version works. Then, you can simply swap the bus implementation out by calling: `postal.configuration.bus = myWayBetterBusImplementation`. * The second way you can extend Postal is to change how the `bindingResolver` works. You may not care for the RabbitMQ-style bindings functionality. No problem! Write your own resolver object that implements a `compare` method and swap the core version out with your implementation by calling: `postal.configuration.resolver = myWayBetterResolver`. -It's also possible to extend the monitoring of messages passing through Postal by adding a "wire tap". A wire tap is a callback that will get invoked for any published message (even if no actual subscriptions would bind to the message's topic). Wire taps should _not_ be used in lieu of an actual subscription - but instead should be used for diagnostics, logging, forwarding or other concerns that fall along those lines. +It's also possible to extend the monitoring of messages passing through Postal by adding a "wire tap". A wire tap is a callback that will get invoked for any published message (even if no actual subscriptions would bind to the message's topic). Wire taps should _not_ be used in lieu of an actual subscription - but instead should be used for diagnostics, logging, forwarding (to a websocket publisher, for example) or other concerns that fall along those lines. ## Can I contribute? Please - by all means! While I hope the API is relatively stable, I'm open to pull requests. (Hint - if you want a feature implemented, a pull request gives it a much higher probability of being included than simply asking me.) As I said, pull requests are most certainly welcome - but please include tests for your additions. Otherwise, it will disappear into the ether. diff --git a/spec/Postal.spec.js b/spec/Postal.spec.js index f2e9b47..23fbaca 100644 --- a/spec/Postal.spec.js +++ b/spec/Postal.spec.js @@ -9,21 +9,19 @@ QUnit.specify("postal.js", function(){ describe("when creating basic subscription", function() { var systemSubscription = {}; before(function(){ - systemSubscription = postal.subscribe({ channel: "postal", topic: "subscription.created", - callback: function(x){ - console.log("on subscription " + JSON.stringify(x)); - if( x.event && - x.event == "subscription.created" && - x.channel == "MyChannel" && - x.topic == "MyTopic") { + callback: function(data, env){ + console.log("on subscription " + JSON.stringify(data)); + if( data.event && + data.event == "subscription.created" && + data.channel == "MyChannel" && + data.topic == "MyTopic") { caughtSubscribeEvent = true; } } }); - subscription = postal.channel({ channel: "MyChannel", topic: "MyTopic" }) .subscribe(function() { }); sub = postal.configuration.bus.subscriptions.MyChannel.MyTopic[0]; @@ -56,7 +54,7 @@ QUnit.specify("postal.js", function(){ it("should have defaulted the subscription context value", function() { assert(sub.context).isNull(); }); - it("should have captured subscription creation event in wire-tap", function() { + it("should have captured subscription creation event", function() { assert(caughtSubscribeEvent).isTrue(); }); }); @@ -68,11 +66,11 @@ QUnit.specify("postal.js", function(){ systemSubscription = postal.subscribe({ channel: "postal", topic: "subscription.*", - callback: function(x){ - if( x.event && - x.event == "subscription.removed" && - x.channel == "MyChannel" && - x.topic == "MyTopic") { + callback: function(data, env){ + if( data.event && + data.event == "subscription.removed" && + data.channel == "MyChannel" && + data.topic == "MyTopic") { caughtUnsubscribeEvent = true; }; } @@ -93,7 +91,7 @@ QUnit.specify("postal.js", function(){ it("subscription should not exist after unsubscribe", function(){ assert(subExistsAfter).isFalse(); }); - it("should have captured unsubscription creation event in wire-tap", function() { + it("should have captured unsubscription creation event", function() { assert(caughtUnsubscribeEvent).isTrue(); }); }); @@ -180,7 +178,7 @@ QUnit.specify("postal.js", function(){ assert(whte).isTrue(); }); }); - describe("When subscribing with one constraint returning true", function(){ + describe("When subscribing with one constraint returning true", function(){ var recvd = false; before(function(){ channel = postal.channel({ channel: "MyChannel", topic: "MyTopic" }); @@ -428,13 +426,13 @@ QUnit.specify("postal.js", function(){ caughtUnsubscribeEvent = false; wireTapData = []; wireTapEnvelope = []; - wiretap = postal.addWireTap(function(envelope, msg) { + wiretap = postal.addWireTap(function(msg, envelope) { wireTapData.push(msg); wireTapEnvelope.push(envelope); }); - postal.publish({ topic: "Oh.Hai.There" }, { data: "I'm in yer bus, tappin' yer subscriptionz..."}); + postal.publish({ data: "I'm in yer bus, tappin' yer subscriptionz..."}, { topic: "Oh.Hai.There" }); wiretap(); - postal.publish({ topic: "Oh.Hai.There" }, { data: "I'm in yer bus, tappin' yer subscriptionz..."}); + postal.publish({ data: "I'm in yer bus, tappin' yer subscriptionz..."}, { topic: "Oh.Hai.There" }); }); after(function(){ postal.configuration.bus.subscriptions = {}; diff --git a/spec/runner.html b/spec/runner.html index 8d0e2fa..4a8919d 100644 --- a/spec/runner.html +++ b/spec/runner.html @@ -28,4 +28,6 @@