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
ad7abc50
Commit
ad7abc50
authored
May 31, 2017
by
yangxiaodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add rabbitmq client.
parent
aa247b19
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
0 deletions
+46
-0
Cap.Consistency.RabbitMQ.csproj
src/Cap.Consistency.RabbitMQ/Cap.Consistency.RabbitMQ.csproj
+4
-0
RabbitMQProducerClient.cs
src/Cap.Consistency.RabbitMQ/RabbitMQProducerClient.cs
+42
-0
No files found.
src/Cap.Consistency.RabbitMQ/Cap.Consistency.RabbitMQ.csproj
View file @
ad7abc50
...
...
@@ -13,4 +13,8 @@
<ProjectReference Include="..\Cap.Consistency\Cap.Consistency.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Microsoft.Extensions.DependencyInjection\" />
</ItemGroup>
</Project>
\ No newline at end of file
src/Cap.Consistency.RabbitMQ/RabbitMQProducerClient.cs
0 → 100644
View file @
ad7abc50
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
System.Threading.Tasks
;
using
Cap.Consistency.Infrastructure
;
using
Cap.Consistency.Producer
;
using
Microsoft.Extensions.Logging
;
using
Microsoft.Extensions.Options
;
using
RabbitMQ.Client
;
namespace
Cap.Consistency.RabbitMQ
{
public
class
RabbitMQProducerClient
:
IProducerClient
{
private
readonly
ConsistencyOptions
_options
;
private
readonly
ILogger
_logger
;
public
RabbitMQProducerClient
(
IOptions
<
ConsistencyOptions
>
options
,
ILoggerFactory
loggerFactory
)
{
_options
=
options
.
Value
;
_logger
=
loggerFactory
.
CreateLogger
(
nameof
(
RabbitMQProducerClient
));
}
public
Task
SendAsync
(
string
topic
,
string
content
)
{
var
factory
=
new
ConnectionFactory
()
{
HostName
=
_options
.
BrokerUrlList
};
using
(
var
connection
=
factory
.
CreateConnection
())
using
(
var
channel
=
connection
.
CreateModel
())
{
channel
.
ExchangeDeclare
(
exchange
:
"topic_logs"
,
type
:
"topic"
);
var
body
=
Encoding
.
UTF8
.
GetBytes
(
content
);
channel
.
BasicPublish
(
exchange
:
"topic_logs"
,
routingKey
:
topic
,
basicProperties
:
null
,
body
:
body
);
return
Task
.
CompletedTask
;
}
}
}
}
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