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
801b3740
Commit
801b3740
authored
Dec 12, 2019
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix postgresql storage bugs
parent
99c12441
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
21 deletions
+17
-21
ValuesController.cs
...s/Sample.Kafka.PostgreSql/Controllers/ValuesController.cs
+4
-7
Startup.cs
samples/Sample.Kafka.PostgreSql/Startup.cs
+4
-5
IDataStorage.PostgreSql.cs
src/DotNetCore.CAP.PostgreSql/IDataStorage.PostgreSql.cs
+7
-7
IStorageInitializer.PostgreSql.cs
...tNetCore.CAP.PostgreSql/IStorageInitializer.PostgreSql.cs
+2
-2
No files found.
samples/Sample.Kafka.PostgreSql/Controllers/ValuesController.cs
View file @
801b3740
...
@@ -21,7 +21,7 @@ namespace Sample.Kafka.PostgreSql.Controllers
...
@@ -21,7 +21,7 @@ namespace Sample.Kafka.PostgreSql.Controllers
[
Route
(
"~/without/transaction"
)]
[
Route
(
"~/without/transaction"
)]
public
async
Task
<
IActionResult
>
WithoutTransaction
()
public
async
Task
<
IActionResult
>
WithoutTransaction
()
{
{
await
_capBus
.
PublishAsync
(
"sample.
rabbitmq.my
sql"
,
DateTime
.
Now
);
await
_capBus
.
PublishAsync
(
"sample.
kafka.postgr
sql"
,
DateTime
.
Now
);
return
Ok
();
return
Ok
();
}
}
...
@@ -36,10 +36,7 @@ namespace Sample.Kafka.PostgreSql.Controllers
...
@@ -36,10 +36,7 @@ namespace Sample.Kafka.PostgreSql.Controllers
//your business code
//your business code
connection
.
Execute
(
"insert into test(name) values('test')"
,
transaction
:
(
IDbTransaction
)
transaction
.
DbTransaction
);
connection
.
Execute
(
"insert into test(name) values('test')"
,
transaction
:
(
IDbTransaction
)
transaction
.
DbTransaction
);
for
(
int
i
=
0
;
i
<
5
;
i
++)
_capBus
.
Publish
(
"sample.kafka.postgrsql"
,
DateTime
.
Now
);
{
_capBus
.
Publish
(
"sample.rabbitmq.mysql"
,
DateTime
.
Now
);
}
transaction
.
Commit
();
transaction
.
Commit
();
}
}
...
@@ -49,8 +46,8 @@ namespace Sample.Kafka.PostgreSql.Controllers
...
@@ -49,8 +46,8 @@ namespace Sample.Kafka.PostgreSql.Controllers
}
}
[
CapSubscribe
(
"
#.test2
"
)]
[
CapSubscribe
(
"
sample.kafka.postgrsql
"
)]
public
void
Test2
(
int
value
)
public
void
Test2
(
DateTime
value
)
{
{
Console
.
WriteLine
(
"Subscriber output message: "
+
value
);
Console
.
WriteLine
(
"Subscriber output message: "
+
value
);
}
}
...
...
samples/Sample.Kafka.PostgreSql/Startup.cs
View file @
801b3740
using
System
;
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.AspNetCore.Builder
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.DependencyInjection
;
namespace
Sample.Kafka.
My
Sql
namespace
Sample.Kafka.
Postgre
Sql
{
{
public
class
Startup
public
class
Startup
{
{
...
@@ -10,8 +9,8 @@ namespace Sample.Kafka.MySql
...
@@ -10,8 +9,8 @@ namespace Sample.Kafka.MySql
{
{
services
.
AddCap
(
x
=>
services
.
AddCap
(
x
=>
{
{
x
.
UsePostgreSql
(
"
Server=localhost;Database=testcap;UserId=root;Password=123123;
"
);
x
.
UsePostgreSql
(
""
);
x
.
UseKafka
(
"
localhost:9092
"
);
x
.
UseKafka
(
""
);
x
.
UseDashboard
();
x
.
UseDashboard
();
});
});
...
...
src/DotNetCore.CAP.PostgreSql/IDataStorage.PostgreSql.cs
View file @
801b3740
...
@@ -45,7 +45,7 @@ namespace DotNetCore.CAP.PostgreSql
...
@@ -45,7 +45,7 @@ namespace DotNetCore.CAP.PostgreSql
await
using
var
connection
=
new
NpgsqlConnection
(
_options
.
Value
.
ConnectionString
);
await
using
var
connection
=
new
NpgsqlConnection
(
_options
.
Value
.
ConnectionString
);
await
connection
.
ExecuteAsync
(
sql
,
new
await
connection
.
ExecuteAsync
(
sql
,
new
{
{
Id
=
message
.
DbId
,
Id
=
long
.
Parse
(
message
.
DbId
)
,
message
.
Retries
,
message
.
Retries
,
message
.
ExpiresAt
,
message
.
ExpiresAt
,
StatusName
=
state
.
ToString
(
"G"
)
StatusName
=
state
.
ToString
(
"G"
)
...
@@ -59,7 +59,7 @@ namespace DotNetCore.CAP.PostgreSql
...
@@ -59,7 +59,7 @@ namespace DotNetCore.CAP.PostgreSql
await
using
var
connection
=
new
NpgsqlConnection
(
_options
.
Value
.
ConnectionString
);
await
using
var
connection
=
new
NpgsqlConnection
(
_options
.
Value
.
ConnectionString
);
await
connection
.
ExecuteAsync
(
sql
,
new
await
connection
.
ExecuteAsync
(
sql
,
new
{
{
Id
=
message
.
DbId
,
Id
=
long
.
Parse
(
message
.
DbId
)
,
message
.
Retries
,
message
.
Retries
,
message
.
ExpiresAt
,
message
.
ExpiresAt
,
StatusName
=
state
.
ToString
(
"G"
)
StatusName
=
state
.
ToString
(
"G"
)
...
@@ -85,13 +85,13 @@ namespace DotNetCore.CAP.PostgreSql
...
@@ -85,13 +85,13 @@ namespace DotNetCore.CAP.PostgreSql
var
po
=
new
var
po
=
new
{
{
Id
=
message
.
DbId
,
Id
=
long
.
Parse
(
message
.
DbId
)
,
Name
=
name
,
Name
=
name
,
message
.
Content
,
message
.
Content
,
message
.
Retries
,
message
.
Retries
,
message
.
Added
,
message
.
Added
,
message
.
ExpiresAt
,
message
.
ExpiresAt
,
StatusName
=
StatusName
.
Scheduled
StatusName
=
nameof
(
StatusName
.
Scheduled
)
};
};
if
(
dbTransaction
==
null
)
if
(
dbTransaction
==
null
)
...
@@ -121,7 +121,7 @@ namespace DotNetCore.CAP.PostgreSql
...
@@ -121,7 +121,7 @@ namespace DotNetCore.CAP.PostgreSql
await
using
var
connection
=
new
NpgsqlConnection
(
_options
.
Value
.
ConnectionString
);
await
using
var
connection
=
new
NpgsqlConnection
(
_options
.
Value
.
ConnectionString
);
await
connection
.
ExecuteAsync
(
sql
,
new
await
connection
.
ExecuteAsync
(
sql
,
new
{
{
Id
=
SnowflakeId
.
Default
().
NextId
()
.
ToString
()
,
Id
=
SnowflakeId
.
Default
().
NextId
(),
Group
=
group
,
Group
=
group
,
Name
=
name
,
Name
=
name
,
Content
=
content
,
Content
=
content
,
...
@@ -150,7 +150,7 @@ namespace DotNetCore.CAP.PostgreSql
...
@@ -150,7 +150,7 @@ namespace DotNetCore.CAP.PostgreSql
await
using
var
connection
=
new
NpgsqlConnection
(
_options
.
Value
.
ConnectionString
);
await
using
var
connection
=
new
NpgsqlConnection
(
_options
.
Value
.
ConnectionString
);
await
connection
.
ExecuteAsync
(
sql
,
new
await
connection
.
ExecuteAsync
(
sql
,
new
{
{
Id
=
mdMessage
.
DbId
,
Id
=
long
.
Parse
(
mdMessage
.
DbId
)
,
Group
=
group
,
Group
=
group
,
Name
=
name
,
Name
=
name
,
Content
=
content
,
Content
=
content
,
...
@@ -168,7 +168,7 @@ namespace DotNetCore.CAP.PostgreSql
...
@@ -168,7 +168,7 @@ namespace DotNetCore.CAP.PostgreSql
await
using
var
connection
=
new
NpgsqlConnection
(
_options
.
Value
.
ConnectionString
);
await
using
var
connection
=
new
NpgsqlConnection
(
_options
.
Value
.
ConnectionString
);
return
await
connection
.
ExecuteAsync
(
return
await
connection
.
ExecuteAsync
(
$"DELETE FROM
{
table
}
WHERE \"ExpiresAt\" < @
now AND \"Id\" IN (SELECT \"Id\" FROM
{
table
}
LIMIT @c
ount);"
,
$"DELETE FROM
{
table
}
WHERE \"ExpiresAt\" < @
timeout AND \"Id\" IN (SELECT \"Id\" FROM
{
table
}
LIMIT @batchC
ount);"
,
new
{
timeout
,
batchCount
});
new
{
timeout
,
batchCount
});
}
}
...
...
src/DotNetCore.CAP.PostgreSql/IStorageInitializer.PostgreSql.cs
View file @
801b3740
...
@@ -53,7 +53,7 @@ namespace DotNetCore.CAP.PostgreSql
...
@@ -53,7 +53,7 @@ namespace DotNetCore.CAP.PostgreSql
var
batchSql
=
$@"
var
batchSql
=
$@"
CREATE SCHEMA IF NOT EXISTS ""
{
schema
}
"";
CREATE SCHEMA IF NOT EXISTS ""
{
schema
}
"";
CREATE TABLE IF NOT EXISTS
{
Get
Publish
edTableName
()}
(
CREATE TABLE IF NOT EXISTS
{
Get
Receiv
edTableName
()}
(
""Id"" BIGINT PRIMARY KEY NOT NULL,
""Id"" BIGINT PRIMARY KEY NOT NULL,
""Version"" VARCHAR(20) NOT NULL,
""Version"" VARCHAR(20) NOT NULL,
""Name"" VARCHAR(200) NOT NULL,
""Name"" VARCHAR(200) NOT NULL,
...
@@ -65,7 +65,7 @@ CREATE TABLE IF NOT EXISTS {GetPublishedTableName()}(
...
@@ -65,7 +65,7 @@ CREATE TABLE IF NOT EXISTS {GetPublishedTableName()}(
""StatusName"" VARCHAR(50) NOT NULL
""StatusName"" VARCHAR(50) NOT NULL
);
);
CREATE TABLE IF NOT EXISTS
{
Get
Receiv
edTableName
()}
(
CREATE TABLE IF NOT EXISTS
{
Get
Publish
edTableName
()}
(
""Id"" BIGINT PRIMARY KEY NOT NULL,
""Id"" BIGINT PRIMARY KEY NOT NULL,
""Version"" VARCHAR(20) NOT NULL,
""Version"" VARCHAR(20) NOT NULL,
""Name"" VARCHAR(200) NOT NULL,
""Name"" VARCHAR(200) NOT NULL,
...
...
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