How to use the seneca.add function in seneca

To help you get started, we’ve selected a few seneca examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github senecajs-attic / getting-started / math-pin-client.js View on Github external
require( 'seneca' )()

  // a local pattern
  .add( 'say:hello', function( msg, respond ){ respond( null, {text:"Hi!"} ) } )

  // send any role:math patterns out over the network
  // IMPORTANT: must match listening service
  .client( { type:'tcp', pin:'role:math' } )

  // executed remotely
  .act('role:math,cmd:sum,left:1,right:2',console.log)

  // executed locally
  .act('say:hello',console.log)
github senecajs / seneca-transport / test / stubs / client-foo-pin.js View on Github external
'use strict'

require('seneca')()

  .add('foo:1,bar:A', function (args, done) {
    done(null, 'localA-' + args.bar)
  })

  .client({pin: {foo: 2, bar: '*'}})

  .add('foo:3,bar:C', function (args, done) {
    done(null, 'localC-' + args.bar)
  })

  .client({pin: {foo: 4, bar: '*'}})

  .add('foo:5,bar:E', function (args, done) {
    done(null, 'localE-' + args.bar)
  })
github senecajs / seneca-mesh / valid / a-d0.js View on Github external
require('seneca')({tag:'d0'})
  //.test('print')
  .add('d:0', function () {
    console.log('D0', this.did, this.fixedargs)
    throw new Error('d0')
  })
  .use('..',{
    pin:'d:*'
  })
github senecajs / seneca-mesh / valid / a-a0.js View on Github external
require('seneca')({tag:'a0'})
  //.test('print')
  .add('a:0')
  .use('..',{
    pin:'a:0'
  })
  .ready(function(){
    this.act('d:0')
  })
github senecajs / ramanujan / docker / timeline / timeline-shard-service.js View on Github external
var HOST = process.env.HOST || process.argv[2] || '127.0.0.1'
var BASES = (process.env.BASES || process.argv[3] || '').split(',')

var _ = require('lodash')

function resolve_shard(user) {
  return user.charCodeAt(0) % 2
}

require('seneca')({
  tag: 'timeline-shard',
  internal: {logger: require('seneca-demo-logger')},
  debug: {short_logs:true}
})
    //.use('zipkin-tracer', {sampling:1})

  .add('timeline:list',function(msg,done){
    var shard = resolve_shard(msg.user)
    this.act({shard:shard},msg,done)
  })

  .add('timeline:insert',function(msg,done){
    var seneca = this
    done()

    var shards = [[],[]]
github senecajs-attic / getting-started / shop-stats.js View on Github external
var stats = {}
require('seneca')()
  .add('role:shop,info:purchase',function( msg, respond ) {
    var product_name = msg.purchase.name
    stats[product_name] = stats[product_name] || 0
    stats[product_name]++
    console.log(stats)
    respond()
  })
  .listen({port:9003,pin:'role:shop,info:purchase'})
github senecajs / ramanujan / timeline / timeline-shard-service.js View on Github external
var HOST = process.env.HOST || process.argv[2] || '127.0.0.1'
var BASES = (process.env.BASES || process.argv[3] || '').split(',')
var SILENT = process.env.SILENT || process.argv[5] || 'true'


var _ = require('lodash')

function resolve_shard(user) {
  return user.charCodeAt(0) % 2
}

require('seneca')({
  tag: 'timeline-shard',
  internal: {logger: require('seneca-demo-logger')},
  debug: {short_logs:true}
})
    //.use('zipkin-tracer', {sampling:1})

  .add('timeline:list',function(msg,done){
    var shard = resolve_shard(msg.user)
    this.act({shard:shard},msg,done)
  })

  .add('timeline:insert',function(msg,done){
    var seneca = this
    done()

    var shards = [[],[]]

seneca

A Microservices Framework for Node.js

MIT
Latest version published 2 months ago

Package Health Score

79 / 100
Full package analysis