Skip to content

Commit b409562

Browse files
committed
Merge branch 'master' of https://github.com/dotnetcore/CAP
2 parents 4243191 + da1ccf1 commit b409562

File tree

12 files changed

+78
-33
lines changed

12 files changed

+78
-33
lines changed

build/version.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<VersionMajor>8</VersionMajor>
44
<VersionMinor>3</VersionMinor>
5-
<VersionPatch>5</VersionPatch>
5+
<VersionPatch>6</VersionPatch>
66
<VersionQuality></VersionQuality>
77
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
88
</PropertyGroup>

docs/content/user-guide/en/cap/messaging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ The following is the content that needs to be written into the header of the mes
9999

100100
| Key | DataType | Description |
101101
| ------------- | -------- | -------------------------------------------------------------- |
102-
| cap-msg-id | string | Message Id, Generated by snowflake algorithm, can also be guid |
102+
| cap-msg-id | long | Message Id, Generated by snowflake algorithm |
103103
| cap-msg-name | string | The name of the message |
104104
| cap-msg-type | string | The type of message, `typeof(T).FullName`(not required) |
105105
| cap-senttime | string | sending time (not required) |

docs/content/user-guide/zh/cap/messaging.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ Body 中的数据为用户发送的原始消息内容,也就是调用 Publish
102102

103103
键 | 类型 | 说明
104104
-- | --| --
105-
cap-msg-id | string | 消息Id, 由雪花算法生成,也可以是 guid
105+
cap-msg-id | long | 消息Id, 由雪花算法生成
106106
cap-msg-name | string | 消息名称,即 Topic 名字
107107
cap-msg-type | string | 消息的类型, 即 typeof(T).FullName (非必须)
108-
cap-senttime | stringg | 发送的时间 (非必须)
108+
cap-senttime | string | 发送的时间 (非必须)
109109

110110
以 Java 系统发送 RabbitMQ 为例:
111111

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Microsoft.EntityFrameworkCore;
2+
3+
namespace Sample.RabbitMQ.MySql
4+
{
5+
public class Person
6+
{
7+
public int Id { get; set; }
8+
9+
public string Name { get; set; }
10+
11+
public int Age { get; set; }
12+
13+
public override string ToString()
14+
{
15+
return $"Name:{Name}, Age:{Age}";
16+
}
17+
}
18+
19+
public class AppDbContext : DbContext
20+
{
21+
public const string ConnectionString = "Server=127.0.0.1;Database=cap;Uid=root;Pwd=my-secret-pw;";
22+
public DbSet<Person> Persons { get; set; }
23+
24+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
25+
{
26+
optionsBuilder.UseMySql(ConnectionString, ServerVersion.AutoDetect(ConnectionString));
27+
}
28+
}
29+
}

samples/Sample.RabbitMQ.MySql/Controllers/ValuesController.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public async Task<IActionResult> Delay(int delaySeconds)
5252
[Route("~/adonet/transaction")]
5353
public async Task<IActionResult> AdonetWithTransaction()
5454
{
55-
using (var connection = new MySqlConnection(Startup.ConnectionString))
55+
using (var connection = new MySqlConnection(AppDbContext.ConnectionString))
5656
{
5757
using var transaction = await connection.BeginTransactionAsync(_capBus, true);
5858
await connection.ExecuteAsync("insert into test(name) values('test')", transaction: (IDbTransaction)transaction.DbTransaction);
@@ -62,18 +62,18 @@ public async Task<IActionResult> AdonetWithTransaction()
6262
return Ok();
6363
}
6464

65-
//[Route("~/ef/transaction")]
66-
//public async Task<IActionResult> EntityFrameworkWithTransaction([FromServices] AppDbContext dbContext)
67-
//{
68-
// using (var trans = await dbContext.Database.BeginTransactionAsync(_capBus, autoCommit: false))
69-
// {
70-
// await dbContext.Persons.AddAsync(new Person() { Name = "ef.transaction" });
71-
// await _capBus.PublishAsync("sample.rabbitmq.mysql", DateTime.Now);
72-
// await dbContext.SaveChangesAsync();
73-
// await trans.CommitAsync();
74-
// }
75-
// return Ok();
76-
//}
65+
[Route("~/ef/transaction")]
66+
public async Task<IActionResult> EntityFrameworkWithTransaction([FromServices] AppDbContext dbContext)
67+
{
68+
using (var trans = await dbContext.Database.BeginTransactionAsync(_capBus, autoCommit: false))
69+
{
70+
await dbContext.Persons.AddAsync(new Person() { Name = "ef.transaction" });
71+
await _capBus.PublishAsync("sample.rabbitmq.mysql", DateTime.Now);
72+
await dbContext.SaveChangesAsync();
73+
await trans.CommitAsync();
74+
}
75+
return Ok();
76+
}
7777

7878
[NonAction]
7979
[CapSubscribe("sample.rabbitmq.mysql")]

samples/Sample.RabbitMQ.MySql/Sample.RabbitMQ.MySql.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<ItemGroup>
88
<PackageReference Include="Dapper" Version="2.0.138" />
99
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
10+
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.3" />
1011
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
1112
</ItemGroup>
1213
<ItemGroup>

samples/Sample.RabbitMQ.MySql/Startup.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ namespace Sample.RabbitMQ.MySql
55
{
66
public class Startup
77
{
8-
public const string ConnectionString = "";
9-
108
public void ConfigureServices(IServiceCollection services)
119
{
10+
services.AddDbContext<AppDbContext>();
11+
1212
services.AddCap(x =>
1313
{
14-
x.UseMySql(ConnectionString);
14+
x.UseEntityFramework<AppDbContext>();
1515
x.UseRabbitMQ("localhost");
1616
x.UseDashboard();
1717
});

samples/Sample.RabbitMQ.MySql/appsettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"Logging": {
33
"LogLevel": {
4-
"Default": "None",
5-
//"DotNetCore.CAP": "Debug",
4+
"Default": "Information",
5+
"DotNetCore.CAP": "Debug",
66
"Microsoft.AspNetCore.Hosting.Diagnostics": "Warning",
77
"Microsoft.AspNetCore.Routing": "Warning"
88
}

src/DotNetCore.CAP.Kafka/IConnectionPool.Default.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,12 @@ public IProducer<string, byte[]> RentProducer()
4141
var config = new ProducerConfig(new Dictionary<string, string>(_options.MainConfig))
4242
{
4343
BootstrapServers = _options.Servers,
44-
QueueBufferingMaxMessages = 10,
45-
MessageTimeoutMs = 5000,
46-
RequestTimeoutMs = 3000
4744
};
4845

46+
config.QueueBufferingMaxMessages ??= 10;
47+
config.MessageTimeoutMs ??= 5000;
48+
config.RequestTimeoutMs ??= 3000;
49+
4950
producer = BuildProducer(config);
5051

5152
return producer;

src/DotNetCore.CAP.MySql/IDataStorage.MySql.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ SELECT Id
217217
FROM `{table}`
218218
WHERE ExpiresAt < @timeout
219219
AND StatusName IN ('{StatusName.Succeeded}', '{StatusName.Failed}')
220+
ORDER BY Id
220221
LIMIT @batchCount
222+
{ (SupportSkipLocked ? "FOR UPDATE SKIP LOCKED" : "FOR UPDATE")}
221223
) AS T ON P.Id = T.Id;",
222224
null,
223225
new MySqlParameter("@timeout", timeout),

0 commit comments

Comments
 (0)