Bus

The bus provides a way to subscribe to events from any of the services running. It's implemented abstract from transport specific implementation. The primary use of the bus in Bitcore Node is for subscribing to events via a web socket.

Opening/Closing


// a node is needed to be able to open a bus
var node = new Node(configuration);

// will create a new bus that is ready to subscribe to events
var bus = node.openBus();

// will remove all event listeners
bus.close();

Subscribing/Unsubscribing


// subscribe to all transaction events
bus.subscribe('bitcoind/rawtransaction');

// to subscribe to new block hashes
bus.subscribe('bitcoind/hashblock');

// unsubscribe
bus.unsubscribe('bitcoind/rawtransaction');

Bus(params)

The bus represents a connection to node, decoupled from the transport layer, that can listen and subscribe to any events that are exposed by available services. Services can expose events that can be subscribed to by implementing a getPublishEvents method.

Kind: global function

Param Type Description
params Object
params.node Node A reference to the node

bus.subscribe(name)

This function will find the service that exposes the event by name and call the associated subscribe method with the arguments excluding the first argument of this function.

Kind: instance method of Bus

Param Type Description
name String The name of the event

bus.unsubscribe(name)

The inverse of the subscribe method.

Kind: instance method of Bus

Param Type Description
name String The name of the event

bus.close()

This function will unsubscribe all events.

Kind: instance method of Bus