Browse Source

chang message id data type from int to long

master
Savorboard 6 years ago
parent
commit
1c0225e847
5 changed files with 21 additions and 17 deletions
  1. +5
    -1
      src/DotNetCore.CAP.MySql/MySqlStorage.cs
  2. +8
    -8
      src/DotNetCore.CAP.MySql/MySqlStorageConnection.cs
  3. +2
    -2
      src/DotNetCore.CAP/Dashboard/DashboardRoutes.cs
  4. +1
    -1
      src/DotNetCore.CAP/Dashboard/Monitoring/MessageDto.cs
  5. +5
    -5
      src/DotNetCore.CAP/IStorageConnection.cs

+ 5
- 1
src/DotNetCore.CAP.MySql/MySqlStorage.cs View File

@@ -81,7 +81,11 @@ CREATE TABLE IF NOT EXISTS `{prefix}.published` (
`ExpiresAt` datetime DEFAULT NULL, `ExpiresAt` datetime DEFAULT NULL,
`StatusName` varchar(40) NOT NULL, `StatusName` varchar(40) NOT NULL,
PRIMARY KEY (`Id`) PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE `{prefix}.published` MODIFY Id BIGINT NOT NULL;
ALTER TABLE `{prefix}.received` MODIFY Id BIGINT NOT NULL;
";
return batchSql; return batchSql;
} }




+ 8
- 8
src/DotNetCore.CAP.MySql/MySqlStorageConnection.cs View File

@@ -30,7 +30,7 @@ namespace DotNetCore.CAP.MySql
return new MySqlStorageTransaction(this); return new MySqlStorageTransaction(this);
} }


public async Task<CapPublishedMessage> GetPublishedMessageAsync(int id)
public async Task<CapPublishedMessage> GetPublishedMessageAsync(long id)
{ {
var sql = $@"SELECT * FROM `{_prefix}.published` WHERE `Id`={id};"; var sql = $@"SELECT * FROM `{_prefix}.published` WHERE `Id`={id};";


@@ -52,7 +52,7 @@ namespace DotNetCore.CAP.MySql
} }
} }


public Task StoreReceivedMessageAsync(CapReceivedMessage message)
public void StoreReceivedMessage(CapReceivedMessage message)
{ {
if (message == null) if (message == null)
{ {
@@ -60,16 +60,16 @@ namespace DotNetCore.CAP.MySql
} }


var sql = $@" var sql = $@"
INSERT INTO `{_prefix}.received`(`Name`,`Group`,`Content`,`Retries`,`Added`,`ExpiresAt`,`StatusName`)
VALUES(@Name,@Group,@Content,@Retries,@Added,@ExpiresAt,@StatusName);";
INSERT INTO `{_prefix}.received`(`Id`,`Name`,`Group`,`Content`,`Retries`,`Added`,`ExpiresAt`,`StatusName`)
VALUES(@Id,@Name,@Group,@Content,@Retries,@Added,@ExpiresAt,@StatusName);";


using (var connection = new MySqlConnection(Options.ConnectionString)) using (var connection = new MySqlConnection(Options.ConnectionString))
{ {
return connection.ExecuteScalarAsync<int>(sql, message);
connection.Execute(sql, message);
} }
} }


public async Task<CapReceivedMessage> GetReceivedMessageAsync(int id)
public async Task<CapReceivedMessage> GetReceivedMessageAsync(long id)
{ {
var sql = $@"SELECT * FROM `{_prefix}.received` WHERE Id={id};"; var sql = $@"SELECT * FROM `{_prefix}.received` WHERE Id={id};";
using (var connection = new MySqlConnection(Options.ConnectionString)) using (var connection = new MySqlConnection(Options.ConnectionString))
@@ -89,7 +89,7 @@ VALUES(@Name,@Group,@Content,@Retries,@Added,@ExpiresAt,@StatusName);";
} }
} }


public bool ChangePublishedState(int messageId, string state)
public bool ChangePublishedState(long messageId, string state)
{ {
var sql = var sql =
$"UPDATE `{_prefix}.published` SET `Retries`=`Retries`+1,`ExpiresAt`=NULL,`StatusName` = '{state}' WHERE `Id`={messageId}"; $"UPDATE `{_prefix}.published` SET `Retries`=`Retries`+1,`ExpiresAt`=NULL,`StatusName` = '{state}' WHERE `Id`={messageId}";
@@ -100,7 +100,7 @@ VALUES(@Name,@Group,@Content,@Retries,@Added,@ExpiresAt,@StatusName);";
} }
} }


public bool ChangeReceivedState(int messageId, string state)
public bool ChangeReceivedState(long messageId, string state)
{ {
var sql = var sql =
$"UPDATE `{_prefix}.received` SET `Retries`=`Retries`+1,`ExpiresAt`=NULL,`StatusName` = '{state}' WHERE `Id`={messageId}"; $"UPDATE `{_prefix}.received` SET `Retries`=`Retries`+1,`ExpiresAt`=NULL,`StatusName` = '{state}' WHERE `Id`={messageId}";


+ 2
- 2
src/DotNetCore.CAP/Dashboard/DashboardRoutes.cs View File

@@ -82,14 +82,14 @@ namespace DotNetCore.CAP.Dashboard


Routes.AddJsonResult("/published/message/(?<Id>.+)", x => Routes.AddJsonResult("/published/message/(?<Id>.+)", x =>
{ {
var id = int.Parse(x.UriMatch.Groups["Id"].Value);
var id = long.Parse(x.UriMatch.Groups["Id"].Value);
var message = x.Storage.GetConnection().GetPublishedMessageAsync(id) var message = x.Storage.GetConnection().GetPublishedMessageAsync(id)
.GetAwaiter().GetResult(); .GetAwaiter().GetResult();
return message.Content; return message.Content;
}); });
Routes.AddJsonResult("/received/message/(?<Id>.+)", x => Routes.AddJsonResult("/received/message/(?<Id>.+)", x =>
{ {
var id = int.Parse(x.UriMatch.Groups["Id"].Value);
var id = long.Parse(x.UriMatch.Groups["Id"].Value);
var message = x.Storage.GetConnection().GetReceivedMessageAsync(id) var message = x.Storage.GetConnection().GetReceivedMessageAsync(id)
.GetAwaiter().GetResult(); .GetAwaiter().GetResult();
return message.Content; return message.Content;


+ 1
- 1
src/DotNetCore.CAP/Dashboard/Monitoring/MessageDto.cs View File

@@ -7,7 +7,7 @@ namespace DotNetCore.CAP.Dashboard.Monitoring
{ {
public class MessageDto public class MessageDto
{ {
public int Id { get; set; }
public long Id { get; set; }


public string Group { get; set; } public string Group { get; set; }




+ 5
- 5
src/DotNetCore.CAP/IStorageConnection.cs View File

@@ -19,7 +19,7 @@ namespace DotNetCore.CAP
/// Returns the message with the given id. /// Returns the message with the given id.
/// </summary> /// </summary>
/// <param name="id">The message's id.</param> /// <param name="id">The message's id.</param>
Task<CapPublishedMessage> GetPublishedMessageAsync(int id);
Task<CapPublishedMessage> GetPublishedMessageAsync(long id);


/// <summary> /// <summary>
/// Returns executed failed messages. /// Returns executed failed messages.
@@ -32,13 +32,13 @@ namespace DotNetCore.CAP
/// Stores the message. /// Stores the message.
/// </summary> /// </summary>
/// <param name="message">The message to store.</param> /// <param name="message">The message to store.</param>
Task StoreReceivedMessageAsync(CapReceivedMessage message);
void StoreReceivedMessage(CapReceivedMessage message);


/// <summary> /// <summary>
/// Returns the message with the given id. /// Returns the message with the given id.
/// </summary> /// </summary>
/// <param name="id">The message's id.</param> /// <param name="id">The message's id.</param>
Task<CapReceivedMessage> GetReceivedMessageAsync(int id);
Task<CapReceivedMessage> GetReceivedMessageAsync(long id);


/// <summary> /// <summary>
/// Returns executed failed message. /// Returns executed failed message.
@@ -55,13 +55,13 @@ namespace DotNetCore.CAP
/// </summary> /// </summary>
/// <param name="messageId">Message id</param> /// <param name="messageId">Message id</param>
/// <param name="state">State name</param> /// <param name="state">State name</param>
bool ChangePublishedState(int messageId, string state);
bool ChangePublishedState(long messageId, string state);


/// <summary> /// <summary>
/// Change specified message's state of received message /// Change specified message's state of received message
/// </summary> /// </summary>
/// <param name="messageId">Message id</param> /// <param name="messageId">Message id</param>
/// <param name="state">State name</param> /// <param name="state">State name</param>
bool ChangeReceivedState(int messageId, string state);
bool ChangeReceivedState(long messageId, string state);
} }
} }

Loading…
Cancel
Save