virtdb-connector v3.0.34
virtdb-connector
Module for connecting node.js based modules to VirtDB.
Usage
npm install virtdb-connector
zmq = require 'zmq'
VirtDBConnector = require 'virtdb-connector'
Const = VirtDBConnector.Constants
proto_meta = (require 'virtdb-proto').meta_data
processMessages = (data) -> # do something great with messages arrived
VirtDBConnector.connect(@name, connectionString)
VirtDBConnector.setupEndpoint (onBound) ->
socket = zmq.socket Const.ZMQ_REP
socket.on "message", (request) ->
try
data = proto_meta.parse request, "virtdb.interface.pb.MetaDataRequest"
processMessages data
catch ex
log.error "Error happened in message receiver: ", V_(ex)
socket.send "err"
socket.bind VirtDBConnector.getConnectionString(), onBound socket, Const.META_DATA, Const.ZMQ_REP
Documentation
connect (name, connectionString, callback)
Connects to the VirtDB system.
- name: the name of component. This name has to be unique throughout a VirtDB installation.
- connectionString: the ZeroMQ connection string of the Endpoint service socket of the Config Service component.
- callback(err): A callback that is called when connection is finished.
getIP()
Returns the own IP address of the current component.
onAddress(service_type, connection_type, callback)
Calls the given callback when an endpoint with the requested service_type and connection_type is published from the Endpoint Service.
- service_type: Possible values: QUERY, COLUMN, META_DATA, DB_CONFIG, DB_CONFIG_QUERY, LOG_RECORD, GET_LOGS, CONFIG, ENDPOINT, IP_DISCOVERY, OTHER, *
- connection_type: Possible values: REQ_REP, PUSH_PULL, PUB_SUB, RAW_UDP
- callback:
function callback(endpoint_name, address, service_type, connection_type)
Where address and connection_type are not always set. Null address means endpoint is deleted.
setupEndpoint(protocol_call)
Set up an endpoint. An endpoint is a service with a given service_type and connection_type that other componenets can connect to. For a possible set of service/connection pairs see the [virtdb-proto](https://github.com/starschema/virtdb-proto) project.
- protocol_call:
function protocol_call(onBound)
onBound:
function onBound(socket, svcType, zmqType)
Callback that has to be called when the ZeroMQ endpoint is set up. It reports the created endpoint to the VirtDB Endpoint Service so that other components get to know about this new endpoint.
subscribe(service_type, callback , channel)
Subscribe for messages of a given type.
- service_type: What types of messages to subscribe for.
- callback:
function callback(channel, message)
Called when messages arrive on the given subscription. - channel: Channel ID to subscribe for. If not set all messages are passed to the callback.
makeConfigurable(template, callback)
Makes the component configurable through the VirtDB config protocol. For a detailed protocol description see the [virtdb-proto](https://github.com/starschema/virtdb-proto) project.
- template: The configuration options of the component.
- callback:
function callback(config)
Called when configuration messages arrive.
sendRequest(name, service_type, message, callback)
Sends a message to the endpoint with the given name and svcType on a ZMQ REQ socket. When the reply arrives the given callback is called. The parsing and serialization of the message with Google Protocol Buffers is the responsibility of the caller.
- name: The name of the component to send the message to.
- service_type: The VirtDB endpoint type of the channel of the component to send the message to.
- message: A message serialized with Protocol Buffers to send to the given endpoint.
- callback(err, reply): The callback hat is called on errors or when received the response.
replyServer(messageHandler, options, callback)
DEPRECATED
Sets up a server that can accept requests on a ZMQ REP socket.
- messageHandler(id, message, sendMethod): The callback is called every time a message arrives on the socket and gives the message as the first argument and a send function as the second. (sendMethod(err, id, reply): The reply is the message that is to be sent back on the socket.)
- options: Possible options are:
- url (required): The url of the endpoint that the endpoint should be listening on. Example format is: tcp://*:12345. Both the IP and the Port part can be ephemeral.
- timeout (default: 3000): As for REQ-REP ZMQ sockets every request has to be replied and if the messageHandler does not call the provided send method in time an empty reply is being sent.
- checkInterval (default: 500): In millisecs how often the timeout is checked.
- emptyMessage (default: ''): The message that is to be sent when the send method is not called in time.
- callback(err, address): A callback that is called when an error happens during the setup or the server is set up and listening.
routerServer(messageHandler, options, callback)
Sets up a server that can accept requests on a ZMQ ROUTER socket.
- messageHandler(id, message, sendMethod): The callback is called every time a message arrives on the socket and gives the message as the first argument and a send function as the second. (sendMethod(err, id, reply): The reply is the message that is to be sent back on the socket.)
- options: Possible options are:
- url (required): The url of the endpoint that the endpoint should be listening on. Example format is: tcp://*:12345. Both the IP and the Port part can be ephemeral.
- timeout (default: 3000): As for REQ-REP ZMQ sockets every request has to be replied and if the messageHandler does not call the provided send method in time an empty reply is being sent.
- checkInterval (default: 500): In millisecs how often the timeout is checked.
- emptyMessage (default: ''): The message that is to be sent when the send method is not called in time.
- callback(err, address): A callback that is called when an error happens during the setup or the server is set up and listening.
More info at: http://www.virtdb.com
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago