Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
vernemq
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
stack
vernemq
Commits
eb5c0866
Commit
eb5c0866
authored
Nov 07, 2018
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
482eee0e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
7 deletions
+15
-7
pubhook/on_publish.js
+15
-7
No files found.
pubhook/on_publish.js
View file @
eb5c0866
var
config
=
require
(
'config'
);
// https://github.com/isaacs/node-lru-cache
var
LRU
=
require
(
"lru-cache"
)
,
cache
=
LRU
({
...
...
@@ -13,6 +14,9 @@ var client = senecaAMQP.client({
url
:
'amqp://'
+
config
.
get
(
'rabbitmq_username'
)
+
':'
+
config
.
get
(
'rabbitmq_password'
)
+
'@'
+
config
.
get
(
'rabbitmq_host'
)
+
':'
+
config
.
get
(
'rabbitmq_port'
)
});
//1----
console
.
log
(
'amqp://'
+
config
.
get
(
'rabbitmq_username'
)
+
':'
+
config
.
get
(
'rabbitmq_password'
)
+
'@'
+
config
.
get
(
'rabbitmq_host'
)
+
':'
+
config
.
get
(
'rabbitmq_port'
));
module
.
exports
=
function
(
options
=
{})
{
return
function
(
req
,
res
,
next
)
{
...
...
@@ -21,7 +25,8 @@ module.exports = function(options={}) {
console
.
log
(
'on_publish-------------'
);
console
.
log
(
req
.
body
);
}
console
.
log
(
123
);
console
.
log
(
data
.
topic
.
substring
(
0
,
5
));
var
data
=
req
.
body
;
if
(
data
.
topic
.
substring
(
0
,
5
)
==
'$exec'
)
{
var
stopic
=
data
.
topic
.
substr
(
6
);
...
...
@@ -32,24 +37,26 @@ module.exports = function(options={}) {
switch
(
a
[
0
])
{
case
'wf'
:
case
'writefeed'
:
let
wfmsg
=
[{
var
wfmsg
=
[{
"topic"
:
stopic
,
"payload"
:
ptext
,
"ts"
:
Date
.
now
(),
"cid"
:
data
.
client_id
,
}];
console
.
log
(
1111
);
console
.
log
(
wfmsg
);
client
.
act
(
'cmd:wf'
,
{
message
:
JSON
.
stringify
(
wfmsg
)
},
(
err
,
res
)
=>
{
if
(
err
)
{
console
.
log
(
err
);
throw
err
;
}
});
break
;
case
'push'
:
let
pushmsg
=
[{
var
pushmsg
=
[{
"topic"
:
stopic
,
"payload"
:
ptext
,
"ts"
:
Date
.
now
(),
...
...
@@ -59,6 +66,7 @@ module.exports = function(options={}) {
message
:
JSON
.
stringify
(
pushmsg
)
},
(
err
,
res
)
=>
{
if
(
err
)
{
console
.
log
(
err
);
throw
err
;
}
});
...
...
@@ -68,9 +76,9 @@ module.exports = function(options={}) {
}
}
var
topic
=
req
.
body
.
topic
;
var
cachekey
=
'pub:'
+
req
.
body
.
client_id
+
':'
+
req
.
body
.
username
+
':'
+
topic
;
var
authstatus
=
cache
.
get
(
cachekey
);
//
var topic = req.body.topic;
//
var cachekey = 'pub:'+req.body.client_id +':'+ req.body.username+':'+topic;
//
var authstatus = cache.get(cachekey);
res
.
status
(
200
);
res
.
send
(
''
);
...
...
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