Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
N
node-bigstream
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bs
node-bigstream
Commits
75b3f5b9
Commit
75b3f5b9
authored
Dec 22, 2016
by
project
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
10e0f94a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
0 deletions
+67
-0
rpcserver.js
lib/amqp/rpcserver.js
+47
-0
test_rpsserv.js
test/test_rpsserv.js
+20
-0
No files found.
lib/amqp/rpcserver.js
0 → 100644
View file @
75b3f5b9
var
amqp
=
require
(
'amqplib/callback_api'
);
function
RPCServer
(
config
)
{
this
.
config
=
config
;
this
.
url
=
config
.
url
;
this
.
name
=
config
.
name
||
"rpc_queue"
;
this
.
remote_function
=
null
;
}
RPCServer
.
prototype
.
start
=
function
(
cb
)
{
var
self
=
this
;
amqp
.
connect
(
self
.
url
,
function
(
err
,
conn
)
{
if
(
err
){
return
cb
(
err
);
}
conn
.
createChannel
(
function
(
err
,
ch
)
{
if
(
err
){
return
cb
(
err
);
}
var
q
=
self
.
name
;
ch
.
assertQueue
(
q
,
{
durable
:
false
});
ch
.
prefetch
(
1
);
console
.
log
(
' [x] Awaiting RPC requests'
);
ch
.
consume
(
q
,
function
reply
(
msg
)
{
var
req
=
JSON
.
parse
(
msg
.
content
.
toString
());
self
.
remote_function
(
req
,
function
(
err
,
resp
){
ch
.
sendToQueue
(
msg
.
properties
.
replyTo
,
new
Buffer
(
JSON
.
stringify
(
resp
)),{
correlationId
:
msg
.
properties
.
correlationId
});
ch
.
ack
(
msg
);
});
});
cb
(
null
);
});
});
}
RPCServer
.
prototype
.
set_remote_function
=
function
(
func
){
this
.
remote_function
=
func
;
}
module
.
exports
=
RPCServer
;
test/test_rpsserv.js
0 → 100644
View file @
75b3f5b9
var
ctx
=
require
(
'../context'
);
var
amqp_cfg
=
ctx
.
config
.
amqp
;
var
rpcserver
=
ctx
.
getLib
(
'lib/amqp/rpcserver'
);
var
server
=
new
rpcserver
({
url
:
"amqp://bigmaster.igridproject.info"
,
});
server
.
set_remote_function
(
function
(
req
,
callback
){
var
n
=
parseInt
(
req
);
console
.
log
(
'REQUEST '
+
req
);
setTimeout
(
function
(){
callback
(
null
,
n
);
},
n
);
})
server
.
start
(
function
(
err
){
console
.
log
(
'server start'
);
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment