Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
egg-puppeteer
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
ui
egg-puppeteer
Commits
73b3ac68
Commit
73b3ac68
authored
May 19, 2020
by
郝聪敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
去掉amqblib
parent
66b1b5eb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
36 deletions
+36
-36
home.js
app/service/home.js
+27
-27
config.default.js
config/config.default.js
+5
-5
plugin.js
config/plugin.js
+4
-4
No files found.
app/service/home.js
View file @
73b3ac68
...
@@ -582,36 +582,36 @@ class HomeService extends Service {
...
@@ -582,36 +582,36 @@ class HomeService extends Service {
}
}
async
publisher
()
{
async
publisher
()
{
const
ch
=
await
this
.
app
.
amqplib
.
createChannel
();
//
const ch = await this.app.amqplib.createChannel();
await
ch
.
assertQueue
(
queueName
,
{
durable
:
false
});
//
await ch.assertQueue(queueName, { durable: false });
for
(
let
i
=
0
;
i
<
5
;
i
++
)
{
//
for (let i = 0; i < 5; i++) {
await
ch
.
sendToQueue
(
queueName
,
Buffer
.
from
(
`第
${
i
}
条消息`
));
//
await ch.sendToQueue(queueName, Buffer.from(`第${i}条消息`));
}
//
}
await
ch
.
close
();
//
await ch.close();
}
}
async
consumer
()
{
async
consumer
()
{
let
ch
;
//
let ch;
try
{
//
try {
ch
=
await
this
.
app
.
amqplib
.
createChannel
();
//
ch = await this.app.amqplib.createChannel();
await
ch
.
assertQueue
(
queueName
,
{
durable
:
false
});
//
await ch.assertQueue(queueName, { durable: false });
await
ch
.
prefetch
(
1
,
false
);
//
await ch.prefetch(1, false);
let
i
=
0
;
//
let i = 0;
await
ch
.
consume
(
queueName
,
msg
=>
{
//
await ch.consume(queueName, msg => {
try
{
//
try {
i
++
;
//
i++;
console
.
log
(
'
consumer
'
,
msg
.
content
.
toString
());
//
console.log('consumer', msg.content.toString());
if
(
i
===
1
)
{
throw
new
Error
(
'
出现异常
'
);
}
//
if (i === 1) { throw new Error('出现异常'); }
ch
.
ack
(
msg
);
//
ch.ack(msg);
}
catch
(
err
)
{
//
} catch (err) {
this
.
ctx
.
logger
.
error
(
err
);
//
this.ctx.logger.error(err);
ch
.
close
();
//
ch.close();
}
//
}
},
{
noAck
:
false
});
//
}, { noAck: false });
}
catch
(
err
)
{
//
} catch (err) {
this
.
ctx
.
logger
.
error
(
err
);
//
this.ctx.logger.error(err);
if
(
ch
)
ch
.
close
();
//
if (ch) ch.close();
}
//
}
}
}
}
}
...
...
config/config.default.js
View file @
73b3ac68
...
@@ -26,11 +26,11 @@ module.exports = appInfo => {
...
@@ -26,11 +26,11 @@ module.exports = appInfo => {
};
};
},
},
},
},
amqplib
:
{
//
amqplib: {
client
:
{
//
client: {
url
:
'
amqp://qa:qatest@172.17.5.8:31342/egg-puppeteer
'
,
//
url: 'amqp://qa:qatest@172.17.5.8:31342/egg-puppeteer',
},
//
},
},
//
},
};
};
// use for cookie sign key, should change to your own and keep security
// use for cookie sign key, should change to your own and keep security
...
...
config/plugin.js
View file @
73b3ac68
...
@@ -2,10 +2,10 @@
...
@@ -2,10 +2,10 @@
/** @type Egg.EggPlugin */
/** @type Egg.EggPlugin */
module
.
exports
=
{
module
.
exports
=
{
amqplib
:
{
//
amqplib: {
enable
:
true
,
//
enable: true,
package
:
'
egg-amqplib
'
,
//
package: 'egg-amqplib',
},
//
},
redis
:
{
redis
:
{
enable
:
true
,
enable
:
true
,
package
:
'
egg-redis
'
,
package
:
'
egg-redis
'
,
...
...
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