3.0.34 • Published 9 years ago

virtdb-connector v3.0.34

Weekly downloads
2
License
LGPL-3.0
Repository
github
Last release
9 years ago

Build Status

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

3.0.34

9 years ago

3.0.32

9 years ago

3.0.31

9 years ago

3.0.30

9 years ago

3.0.29

9 years ago

3.0.27

9 years ago

3.0.26

9 years ago

3.0.25

9 years ago

3.0.24

9 years ago

3.0.23

9 years ago

3.0.22

9 years ago

3.0.21

9 years ago

3.0.20

9 years ago

3.0.19

9 years ago

3.0.18

9 years ago

3.0.16

9 years ago

3.0.15

9 years ago

3.0.14

9 years ago

3.0.13

9 years ago

3.0.12

9 years ago

3.0.11

9 years ago

3.0.10

9 years ago

3.0.9

9 years ago

3.0.8

9 years ago

3.0.7

9 years ago

3.0.6

9 years ago

3.0.5

9 years ago

3.0.3

9 years ago

3.0.2

9 years ago

3.0.1

9 years ago

2.1.3

9 years ago

2.1.2

9 years ago

2.1.1

9 years ago

2.0.1

9 years ago

1.6.18

9 years ago

1.6.15

9 years ago

1.6.14

9 years ago

1.6.13

9 years ago

1.6.12

9 years ago

1.6.11

9 years ago

1.6.10

9 years ago

1.6.9

9 years ago

1.6.8

9 years ago

1.6.7

9 years ago

1.6.6

9 years ago

1.6.5

9 years ago

1.6.4

9 years ago

1.6.3

9 years ago

1.6.2

9 years ago

1.6.1

9 years ago

1.5.5

9 years ago

1.5.4

9 years ago

1.5.3

9 years ago

1.5.2

9 years ago

1.5.1

9 years ago

1.4.12

9 years ago

1.4.11

9 years ago

1.4.10

9 years ago

1.4.9

9 years ago

1.4.8

9 years ago

1.4.7

9 years ago

1.4.6

9 years ago

1.4.5

9 years ago

1.4.4

9 years ago

1.4.3

9 years ago

1.4.2

9 years ago

1.4.1

9 years ago

1.3.4

9 years ago

1.2.3

9 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.1.5

9 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.0.25

10 years ago

1.0.24

10 years ago

1.0.23

10 years ago

1.0.22

10 years ago

1.0.21

10 years ago

1.0.20

10 years ago

1.0.19

10 years ago

1.0.15

10 years ago

1.0.13

10 years ago

1.0.11

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago