Commit 3d7eb4bc authored by yangxiaodong's avatar yangxiaodong

Change exhcange type with options.

parent 725b4677
...@@ -94,16 +94,9 @@ namespace DotNetCore.CAP.RabbitMQ ...@@ -94,16 +94,9 @@ namespace DotNetCore.CAP.RabbitMQ
sp.Stop(); sp.Stop();
if (!jobResult) if (jobResult)
{ {
_logger.JobFailed(new Exception("topic send failed")); await messageStore.RemoveSentMessageAsync(message);
}
else
{
//TODO : the state will be deleted when release.
message.StatusName = StatusName.Succeeded;
await messageStore.UpdateSentMessageAsync(message);
_logger.JobExecuted(sp.Elapsed.TotalSeconds); _logger.JobExecuted(sp.Elapsed.TotalSeconds);
} }
} }
...@@ -135,10 +128,10 @@ namespace DotNetCore.CAP.RabbitMQ ...@@ -135,10 +128,10 @@ namespace DotNetCore.CAP.RabbitMQ
using (var connection = factory.CreateConnection()) using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel()) using (var channel = connection.CreateModel())
{ {
channel.ExchangeDeclare(exchange: "test",
type: "topic");
var body = Encoding.UTF8.GetBytes(content); var body = Encoding.UTF8.GetBytes(content);
channel.BasicPublish(exchange: "test",
channel.ExchangeDeclare(_rabbitMQOptions.TopicExchangeName, _rabbitMQOptions.EXCHANGE_TYPE);
channel.BasicPublish(exchange: _rabbitMQOptions.TopicExchangeName,
routingKey: topic, routingKey: topic,
basicProperties: null, basicProperties: null,
body: body); body: body);
......
...@@ -9,10 +9,8 @@ namespace DotNetCore.CAP.RabbitMQ ...@@ -9,10 +9,8 @@ namespace DotNetCore.CAP.RabbitMQ
{ {
public class RabbitMQConsumerClient : IConsumerClient public class RabbitMQConsumerClient : IConsumerClient
{ {
public const string TYPE = "topic"; private readonly string _exchageName;
private readonly string _queueName;
private string _queueName;
private readonly string _exchange;
private readonly RabbitMQOptions _rabbitMQOptions; private readonly RabbitMQOptions _rabbitMQOptions;
private IConnectionFactory _connectionFactory; private IConnectionFactory _connectionFactory;
...@@ -21,10 +19,11 @@ namespace DotNetCore.CAP.RabbitMQ ...@@ -21,10 +19,11 @@ namespace DotNetCore.CAP.RabbitMQ
public event EventHandler<MessageBase> MessageReceieved; public event EventHandler<MessageBase> MessageReceieved;
public RabbitMQConsumerClient(string exchange, RabbitMQOptions options) public RabbitMQConsumerClient(string queueName, RabbitMQOptions options)
{ {
_exchange = exchange; _queueName = queueName;
_rabbitMQOptions = options; _rabbitMQOptions = options;
_exchageName = options.TopicExchangeName;
InitClient(); InitClient();
} }
...@@ -45,8 +44,8 @@ namespace DotNetCore.CAP.RabbitMQ ...@@ -45,8 +44,8 @@ namespace DotNetCore.CAP.RabbitMQ
_connection = _connectionFactory.CreateConnection(); _connection = _connectionFactory.CreateConnection();
_channel = _connection.CreateModel(); _channel = _connection.CreateModel();
_channel.ExchangeDeclare(exchange: _exchange, type: TYPE); _channel.ExchangeDeclare(exchange: _exchageName, type: _rabbitMQOptions.EXCHANGE_TYPE);
_queueName = _channel.QueueDeclare().QueueName; _channel.QueueDeclare(_queueName);
} }
public void Listening(TimeSpan timeout) public void Listening(TimeSpan timeout)
...@@ -62,12 +61,12 @@ namespace DotNetCore.CAP.RabbitMQ ...@@ -62,12 +61,12 @@ namespace DotNetCore.CAP.RabbitMQ
public void Subscribe(string topic) public void Subscribe(string topic)
{ {
_channel.QueueBind(_queueName, _exchange, topic); _channel.QueueBind(_queueName, _exchageName, topic);
} }
public void Subscribe(string topic, int partition) public void Subscribe(string topic, int partition)
{ {
_channel.QueueBind(_queueName, _exchange, topic); _channel.QueueBind(_queueName, _exchageName, topic);
} }
public void Dispose() public void Dispose()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment