Skip to content

Commit 0fa1ef5

Browse files
author
oujun
committed
临时提交,新版本的设计
1 parent 7fd1f37 commit 0fa1ef5

38 files changed

Lines changed: 1365 additions & 1195 deletions

RabbitMQ.EventBus.AspNetCore.Sample/Controllers/MessageBody1.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

RabbitMQ.EventBus.AspNetCore.Sample/Controllers/MessageBodyHandle.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace RabbitMQ.EventBus.AspNetCore.Simple.Controllers
77
{
8-
public class MessageBodyHandle : IEventHandler<MessageBody1>, IDisposable
8+
public class MessageBodyHandle : IEventResponseHandler<MessageBody, string>, IDisposable
99
{
1010
private Guid id;
1111
private readonly ILogger<MessageBodyHandle> _logger;
@@ -17,18 +17,13 @@ public MessageBodyHandle(ILogger<MessageBodyHandle> logger)
1717
}
1818
public void Dispose()
1919
{
20-
Console.WriteLine("释放");
20+
_logger.LogInformation("MessageBodyHandle Disposable.");
2121
}
2222

23-
public Task Handle(EventHandlerArgs<MessageBody1> args)
23+
24+
public Task<string> HandleAsync(HandlerEventArgs<MessageBody> args)
2425
{
25-
Console.WriteLine("==================================================");
26-
Console.WriteLine(id + "=>" + typeof(MessageBody1).Name);
27-
Console.WriteLine(args.Event.Body);
28-
Console.WriteLine(args.Original);
29-
Console.WriteLine(args.Redelivered);
30-
Console.WriteLine("==================================================");
31-
return Task.CompletedTask;
26+
return Task.FromResult("收到消息,已确认");
3227
}
3328
}
3429
}

RabbitMQ.EventBus.AspNetCore.Sample/Controllers/MessageBodyHandle00.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

RabbitMQ.EventBus.AspNetCore.Sample/Controllers/MessageBodyHandle111.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

RabbitMQ.EventBus.AspNetCore.Sample/Controllers/ValuesController.cs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.AspNetCore.Mvc;
2+
using Newtonsoft.Json;
23
using System;
34
using System.Threading.Tasks;
45

@@ -19,23 +20,18 @@ public ValuesController(IRabbitMQEventBus eventBus)
1920
[HttpGet]
2021
public async Task<ActionResult<string>> Get()
2122
{
22-
//_eventBus.Publish(new
23-
//{
24-
// Body = "rabbitmq.eventbus.test=>发送消息",
25-
// Time = DateTimeOffset.Now
26-
//}, exchange: "RabbitMQ.EventBus.Simple", routingKey: "rabbitmq.eventbus.test");
2723

28-
for (int i = 0; i < 1000; i++)
24+
Console.WriteLine($"发送消息{1}");
25+
var body = new
2926
{
30-
_eventBus.Publish(new
31-
{
32-
Body = $"rabbitmq.eventbus.test1=>发送消息/t{i}",
33-
Time = DateTimeOffset.Now,
34-
}, exchange: "RabbitMQ.EventBus.Simple", routingKey: "rabbitmq.eventbus.test1");
35-
await Task.Yield();
36-
await Task.Delay(500);
37-
}
38-
return "Ok";
27+
requestId = Guid.NewGuid(),
28+
Body = $"rabbitmq.eventbus.test=>发送消息/t{1}",
29+
Time = DateTimeOffset.Now,
30+
};
31+
var r = await _eventBus.PublishAsync<string>(body, exchange: "RabbitMQ.EventBus.Simple", routingKey: "rabbitmq.eventbus.test");
32+
Console.WriteLine($"返回了{r}");
33+
await Task.Delay(500);
34+
return r;
3935
}
4036

4137
// GET api/values/5

RabbitMQ.EventBus.AspNetCore.Sample/RabbitMQ.EventBus.AspNetCore.Sample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
66
<IncludeOpenAPIAnalyzers>true</IncludeOpenAPIAnalyzers>
77
</PropertyGroup>

RabbitMQ.EventBus.AspNetCore.Sample/Startup.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ public void ConfigureServices(IServiceCollection services)
2727
services.AddControllers();
2828
services.AddHealthChecks();
2929

30-
services.AddRabbitMQEventBus(() => "amqp://guest:guest@localhost:5672/", eventBusOptionAction: eventBusOption =>
31-
{
32-
eventBusOption.ClientProvidedAssembly(assemblyName);
33-
eventBusOption.EnableRetryOnFailure(true, 5000, TimeSpan.FromSeconds(30));
34-
eventBusOption.RetryOnFailure(TimeSpan.FromSeconds(1));
35-
eventBusOption.MessageTTL(2000);
36-
eventBusOption.SetBasicQos(10);
37-
eventBusOption.DeadLetterExchangeConfig(config =>
38-
{
39-
config.Enabled = true;
40-
config.ExchangeNameSuffix = "-test";
41-
});
42-
});
30+
services.AddRabbitMQEventBus(() => "amqp://guest:guest@172.30.239.244:5672/", eventBusOptionAction: eventBusOption =>
31+
{
32+
eventBusOption.ClientProvidedAssembly(assemblyName);
33+
eventBusOption.EnableRetryOnFailure(true, 5000, TimeSpan.FromSeconds(30));
34+
eventBusOption.RetryOnFailure(TimeSpan.FromSeconds(1));
35+
eventBusOption.MessageTTL(2000);
36+
eventBusOption.SetBasicQos(10);
37+
eventBusOption.DeadLetterExchangeConfig(config =>
38+
{
39+
config.Enabled = false;
40+
config.ExchangeNameSuffix = "-test";
41+
});
42+
});
4343
}
4444

4545
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -50,7 +50,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
5050
app.UseDeveloperExceptionPage();
5151
}
5252
app.UseRouting();
53-
app.RabbitMQEventBusAutoSubscribe();
5453
app.UseEndpoints(endpoints =>
5554
{
5655
endpoints.MapControllers();

RabbitMQ.EventBus.AspNetCore.Sample/appsettings.Development.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"Logging": {
33
"LogLevel": {
44
"Default": "Debug",
5-
"System": "Information",
6-
"Microsoft": "Information"
5+
"System": "Debug",
6+
"Microsoft": "Debug"
77
}
88
}
99
}

RabbitMQ.EventBus.AspNetCore.Sample/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"Logging": {
33
"LogLevel": {
4-
"Default": "Warning"
4+
"Default": "Debug"
55
}
66
},
77
"AllowedHosts": "*"
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
using System;
2-
3-
namespace RabbitMQ.EventBus.AspNetCore.Attributes
1+
namespace RabbitMQ.EventBus.AspNetCore.Attributes;
2+
/// <summary>
3+
///
4+
/// </summary>
5+
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
6+
public class EventBusAttribute : Attribute
47
{
8+
/// <summary>
9+
/// 队列名
10+
/// </summary>
11+
public string Queue { get; set; }
12+
/// <summary>
13+
/// 交换机名
14+
/// </summary>
15+
public string Exchange { get; set; }
16+
/// <summary>
17+
/// 路由Key
18+
/// </summary>
19+
public string RoutingKey { get; set; }
20+
/// <summary>
21+
/// Configures QoS parameters of the Basic content-class.
22+
/// </summary>
23+
public ushort? BasicQos { get; set; }
524
/// <summary>
625
///
726
/// </summary>
8-
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
9-
public class EventBusAttribute : Attribute
27+
public EventBusAttribute()
1028
{
11-
/// <summary>
12-
/// 队列名
13-
/// </summary>
14-
public string Queue { get; set; }
15-
/// <summary>
16-
/// 交换机名
17-
/// </summary>
18-
public string Exchange { get; set; }
19-
/// <summary>
20-
/// 路由Key
21-
/// </summary>
22-
public string RoutingKey { get; set; }
23-
/// <summary>
24-
///
25-
/// </summary>
26-
public EventBusAttribute()
27-
{
28-
RoutingKey = "";
29-
}
29+
RoutingKey = "";
3030
}
31-
}
31+
}

0 commit comments

Comments
 (0)