Skip to content

Commit 9689ddf

Browse files
authored
Merge pull request #51 from ojdev/dev
大版本升级
2 parents 3a22e83 + a8701d3 commit 9689ddf

39 files changed

Lines changed: 1356 additions & 1234 deletions

.github/workflows/dotnetcore.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ jobs:
3030
- name: Build with dotnet
3131
run: dotnet build --configuration Release src/RabbitMQ.EventBus.AspNetCore
3232
- name: Pack
33-
run: dotnet pack src/RabbitMQ.EventBus.AspNetCore -c Release --include-symbols --include-source -p:PackageVersion=5.0.$GITHUB_RUN_NUMBER -o artifacts/
33+
run: dotnet pack src/RabbitMQ.EventBus.AspNetCore -c Release --include-symbols --include-source -p:PackageVersion=${{steps.tag.outputs.tag}} -o artifacts/
3434
- name: Publish Symbols to NuGet
3535
run: dotnet nuget push artifacts/*.symbols.nupkg --api-key ${{secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json

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: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,27 @@
55

66
namespace RabbitMQ.EventBus.AspNetCore.Simple.Controllers
77
{
8-
public class MessageBodyHandle : IEventHandler<MessageBody1>, IDisposable
8+
public class MessageBodyHandle : IEventResponseHandler<MessageBody, string>, IDisposable
9+
{
10+
private Guid id;
11+
private readonly ILogger<MessageBodyHandle> _logger;
12+
13+
public MessageBodyHandle(ILogger<MessageBodyHandle> logger)
914
{
10-
private Guid id;
11-
private readonly ILogger<MessageBodyHandle> _logger;
15+
id = Guid.NewGuid();
16+
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
17+
}
18+
public void Dispose()
19+
{
20+
_logger.LogInformation("MessageBodyHandle Disposable.");
21+
}
1222

13-
public MessageBodyHandle(ILogger<MessageBodyHandle> logger)
14-
{
15-
id = Guid.NewGuid();
16-
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
17-
}
18-
public void Dispose()
19-
{
20-
Console.WriteLine("释放");
21-
}
2223

23-
public Task Handle(EventHandlerArgs<MessageBody1> args)
24-
{
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;
32-
}
24+
public Task<string> HandleAsync(HandlerEventArgs<MessageBody> args)
25+
{
26+
return Task.FromResult("收到消息,已确认" + DateTimeOffset.Now);
3327
}
3428
}
29+
30+
31+
}

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.
Lines changed: 11 additions & 41 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,48 +20,17 @@ 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");
27-
28-
for (int i = 0; i < 1000; i++)
23+
Console.WriteLine($"发送消息{1}");
24+
var body = new
2925
{
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";
39-
}
40-
41-
// GET api/values/5
42-
[HttpGet("{id}")]
43-
public ActionResult<string> Get(int id)
44-
{
45-
return "value";
46-
}
47-
48-
// POST api/values
49-
[HttpPost]
50-
public void Post([FromBody] string value)
51-
{
52-
}
53-
54-
// PUT api/values/5
55-
[HttpPut("{id}")]
56-
public void Put(int id, [FromBody] string value)
57-
{
58-
}
59-
60-
// DELETE api/values/5
61-
[HttpDelete("{id}")]
62-
public void Delete(int id)
63-
{
26+
requestId = Guid.NewGuid(),
27+
Body = $"rabbitmq.eventbus.test=>发送消息\t{1}",
28+
Time = DateTimeOffset.Now,
29+
};
30+
var r = await _eventBus.PublishAsync<string>(body, exchange: "RabbitMQ.EventBus.Simple", routingKey: "rabbitmq.eventbus.test");
31+
Console.WriteLine($"返回了{r}");
32+
await Task.Delay(500);
33+
return r;
6434
}
6535
}
6636
}

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: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,35 @@ 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+
31+
services.AddRabbitMQEventBus("localhost", 5672, "guest", "guest", "", eventBusOptionAction: eventBusOption =>
32+
{
33+
eventBusOption.ClientProvidedAssembly(assemblyName);
34+
eventBusOption.EnableRetryOnFailure(true, 5000, TimeSpan.FromSeconds(30));
35+
eventBusOption.RetryOnFailure(TimeSpan.FromSeconds(1));
36+
eventBusOption.MessageTTL(2000);
37+
eventBusOption.SetBasicQos(10);
38+
eventBusOption.DeadLetterExchangeConfig(config =>
39+
{
40+
config.Enabled = false;
41+
config.ExchangeNameSuffix = "-test";
42+
});
43+
});
44+
//or
45+
//
46+
//services.AddRabbitMQEventBus(() => "amqp://guest:guest@localhost:5672/", eventBusOptionAction: eventBusOption =>
47+
//{
48+
// eventBusOption.ClientProvidedAssembly(assemblyName);
49+
// eventBusOption.EnableRetryOnFailure(true, 5000, TimeSpan.FromSeconds(30));
50+
// eventBusOption.RetryOnFailure(TimeSpan.FromSeconds(1));
51+
// eventBusOption.MessageTTL(2000);
52+
// eventBusOption.SetBasicQos(10);
53+
// eventBusOption.DeadLetterExchangeConfig(config =>
54+
// {
55+
// config.Enabled = false;
56+
// config.ExchangeNameSuffix = "-test";
57+
// });
58+
//});
4359
}
4460

4561
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -50,7 +66,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
5066
app.UseDeveloperExceptionPage();
5167
}
5268
app.UseRouting();
53-
app.RabbitMQEventBusAutoSubscribe();
5469
app.UseEndpoints(endpoints =>
5570
{
5671
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": "*"

0 commit comments

Comments
 (0)