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
0476ed43
Commit
0476ed43
authored
May 26, 2017
by
yangxiaodong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add rabbitmq proejct
parent
3306e2c4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
117 additions
and
0 deletions
+117
-0
Cap.Consistency.RabbitMQ.csproj
src/Cap.Consistency.RabbitMQ/Cap.Consistency.RabbitMQ.csproj
+16
-0
RabbitMQConsumerClient.cs
src/Cap.Consistency.RabbitMQ/RabbitMQConsumerClient.cs
+72
-0
RabbitMQConsumerClientFactory.cs
...Cap.Consistency.RabbitMQ/RabbitMQConsumerClientFactory.cs
+14
-0
RabbitMQTopicAttribute.cs
src/Cap.Consistency.RabbitMQ/RabbitMQTopicAttribute.cs
+15
-0
No files found.
src/Cap.Consistency.RabbitMQ/Cap.Consistency.RabbitMQ.csproj
0 → 100644
View file @
0476ed43
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.6</TargetFramework>
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RabbitMQ.Client" Version="5.0.1-rc1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Cap.Consistency\Cap.Consistency.csproj" />
</ItemGroup>
</Project>
\ No newline at end of file
src/Cap.Consistency.RabbitMQ/RabbitMQConsumerClient.cs
0 → 100644
View file @
0476ed43
using
System
;
using
System.Text
;
using
System.Threading.Tasks
;
using
Cap.Consistency.Consumer
;
using
Cap.Consistency.Infrastructure
;
using
RabbitMQ.Client
;
using
RabbitMQ.Client.Events
;
namespace
Cap.Consistency.RabbitMQ
{
public
class
RabbitMQConsumerClient
:
IConsumerClient
{
public
const
string
TYPE
=
"topic"
;
private
readonly
string
_exchange
;
private
readonly
string
_hostName
;
private
IConnectionFactory
_connectionFactory
;
private
IConnection
_connection
;
private
IModel
_channel
;
private
string
_queueName
;
public
event
EventHandler
<
DeliverMessage
>
MessageReceieved
;
public
RabbitMQConsumerClient
(
string
exchange
,
string
hostName
)
{
_exchange
=
exchange
;
_hostName
=
hostName
;
InitClient
();
}
private
void
InitClient
()
{
_connectionFactory
=
new
ConnectionFactory
{
HostName
=
_hostName
};
_connection
=
_connectionFactory
.
CreateConnection
();
_channel
=
_connection
.
CreateModel
();
_channel
.
ExchangeDeclare
(
exchange
:
_exchange
,
type
:
TYPE
);
_queueName
=
_channel
.
QueueDeclare
().
QueueName
;
}
public
void
Listening
(
TimeSpan
timeout
)
{
// Task.Delay(timeout).Wait();
var
consumer
=
new
EventingBasicConsumer
(
_channel
);
consumer
.
Received
+=
OnConsumerReceived
;
_channel
.
BasicConsume
(
_queueName
,
true
,
consumer
);
}
public
void
Subscribe
(
string
topic
)
{
_channel
.
QueueBind
(
_queueName
,
_exchange
,
topic
);
}
public
void
Subscribe
(
string
topic
,
int
partition
)
{
_channel
.
QueueBind
(
_queueName
,
_exchange
,
topic
);
}
public
void
Dispose
()
{
_channel
.
Dispose
();
_connection
.
Dispose
();
}
private
void
OnConsumerReceived
(
object
sender
,
BasicDeliverEventArgs
e
)
{
var
message
=
new
DeliverMessage
{
MessageKey
=
e
.
RoutingKey
,
Body
=
e
.
Body
,
Value
=
Encoding
.
UTF8
.
GetString
(
e
.
Body
)
};
MessageReceieved
?.
Invoke
(
sender
,
message
);
}
}
}
src/Cap.Consistency.RabbitMQ/RabbitMQConsumerClientFactory.cs
0 → 100644
View file @
0476ed43
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
Cap.Consistency.Consumer
;
namespace
Cap.Consistency.RabbitMQ
{
public
class
RabbitMQConsumerClientFactory
:
IConsumerClientFactory
{
public
IConsumerClient
Create
(
string
groupId
,
string
clientHostAddress
)
{
return
new
RabbitMQConsumerClient
(
groupId
,
clientHostAddress
);
}
}
}
src/Cap.Consistency.RabbitMQ/RabbitMQTopicAttribute.cs
0 → 100644
View file @
0476ed43
using
System
;
using
System.Collections.Generic
;
using
System.Text
;
using
Cap.Consistency.Abstractions
;
namespace
Cap.Consistency.RabbitMQ
{
public
class
RabbitMQTopicAttribute
:
TopicAttribute
{
public
RabbitMQTopicAttribute
(
string
routingKey
)
:
base
(
routingKey
)
{
}
}
}
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