Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
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
tsai
CAP
Commits
a31b5812
Commit
a31b5812
authored
Sep 08, 2017
by
yangxiaodong
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/dev_2.0' into dashboard
parents
695777c8
975fcb7d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
10 deletions
+18
-10
ConnectionPool.cs
src/DotNetCore.CAP.RabbitMQ/ConnectionPool.cs
+1
-1
PublishQueueExecutor.cs
src/DotNetCore.CAP.RabbitMQ/PublishQueueExecutor.cs
+6
-1
RabbitMQConsumerClient.cs
src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs
+8
-5
RabbitMQConsumerClientFactory.cs
src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClientFactory.cs
+3
-3
No files found.
src/DotNetCore.CAP.RabbitMQ/ConnectionPool.cs
View file @
a31b5812
...
...
@@ -8,7 +8,7 @@ namespace DotNetCore.CAP.RabbitMQ
{
public
class
ConnectionPool
:
IConnectionPool
,
IDisposable
{
private
const
int
DefaultPoolSize
=
32
;
private
const
int
DefaultPoolSize
=
15
;
private
readonly
ConcurrentQueue
<
IConnection
>
_pool
=
new
ConcurrentQueue
<
IConnection
>();
...
...
src/DotNetCore.CAP.RabbitMQ/PublishQueueExecutor.cs
View file @
a31b5812
...
...
@@ -28,9 +28,10 @@ namespace DotNetCore.CAP.RabbitMQ
public
override
Task
<
OperateResult
>
PublishAsync
(
string
keyName
,
string
content
)
{
var
connection
=
_connectionPool
.
Rent
();
try
{
var
connection
=
_connectionPool
.
Rent
();
using
(
var
channel
=
connection
.
CreateModel
())
{
var
body
=
Encoding
.
UTF8
.
GetBytes
(
content
);
...
...
@@ -56,6 +57,10 @@ namespace DotNetCore.CAP.RabbitMQ
Description
=
ex
.
Message
}));
}
finally
{
_connectionPool
.
Return
(
connection
);
}
}
}
}
\ No newline at end of file
src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClient.cs
View file @
a31b5812
...
...
@@ -14,7 +14,7 @@ namespace DotNetCore.CAP.RabbitMQ
private
readonly
string
_queueName
;
private
readonly
RabbitMQOptions
_rabbitMQOptions
;
private
IConnection
_connection
;
private
ConnectionPool
_connectionPool
;
private
IModel
_channel
;
private
ulong
_deliveryTag
;
...
...
@@ -23,11 +23,11 @@ namespace DotNetCore.CAP.RabbitMQ
public
event
EventHandler
<
string
>
OnError
;
public
RabbitMQConsumerClient
(
string
queueName
,
IConnection
connection
,
ConnectionPool
connectionPool
,
RabbitMQOptions
options
)
{
_queueName
=
queueName
;
_connection
=
connection
;
_connection
Pool
=
connectionPool
;
_rabbitMQOptions
=
options
;
_exchageName
=
options
.
TopicExchangeName
;
...
...
@@ -36,7 +36,9 @@ namespace DotNetCore.CAP.RabbitMQ
private
void
InitClient
()
{
_channel
=
_connection
.
CreateModel
();
var
connection
=
_connectionPool
.
Rent
();
_channel
=
connection
.
CreateModel
();
_channel
.
ExchangeDeclare
(
exchange
:
_exchageName
,
...
...
@@ -49,6 +51,8 @@ namespace DotNetCore.CAP.RabbitMQ
exclusive
:
false
,
autoDelete
:
false
,
arguments
:
arguments
);
_connectionPool
.
Return
(
connection
);
}
public
void
Subscribe
(
IEnumerable
<
string
>
topics
)
...
...
@@ -81,7 +85,6 @@ namespace DotNetCore.CAP.RabbitMQ
public
void
Dispose
()
{
_channel
.
Dispose
();
_connection
.
Dispose
();
}
private
void
OnConsumerReceived
(
object
sender
,
BasicDeliverEventArgs
e
)
...
...
src/DotNetCore.CAP.RabbitMQ/RabbitMQConsumerClientFactory.cs
View file @
a31b5812
...
...
@@ -6,18 +6,18 @@ namespace DotNetCore.CAP.RabbitMQ
internal
sealed
class
RabbitMQConsumerClientFactory
:
IConsumerClientFactory
{
private
readonly
RabbitMQOptions
_rabbitMQOptions
;
private
readonly
IConnection
_connection
;
private
readonly
ConnectionPool
_connectionPool
;
public
RabbitMQConsumerClientFactory
(
RabbitMQOptions
rabbitMQOptions
,
ConnectionPool
pool
)
{
_rabbitMQOptions
=
rabbitMQOptions
;
_connection
=
pool
.
Rent
()
;
_connection
Pool
=
pool
;
}
public
IConsumerClient
Create
(
string
groupId
)
{
return
new
RabbitMQConsumerClient
(
groupId
,
_connection
,
_rabbitMQOptions
);
return
new
RabbitMQConsumerClient
(
groupId
,
_connection
Pool
,
_rabbitMQOptions
);
}
}
}
\ No newline at end of file
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