Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
'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)
})
require('seneca')({tag:'d0'})
//.test('print')
.add('d:0', function () {
console.log('D0', this.did, this.fixedargs)
throw new Error('d0')
})
.use('..',{
pin:'d:*'
})
require('seneca')({tag:'a0'})
//.test('print')
.add('a:0')
.use('..',{
pin:'a:0'
})
.ready(function(){
this.act('d:0')
})
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 = [[],[]]
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'})
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 = [[],[]]