Add Redis timestamp
This commit is contained in:
parent
b01acea3a5
commit
a14981e032
|
|
@ -24,7 +24,11 @@ public class RedisPublisher : IEventPublisher
|
|||
{
|
||||
var db = _redis.GetDatabase();
|
||||
// Add a message to the stream, keeping only the latest 1 million messages
|
||||
await db.StreamAddAsync(channel, "message", message,
|
||||
await db.StreamAddAsync(channel,
|
||||
[
|
||||
new NameValueEntry("message", message),
|
||||
new NameValueEntry("timestamp", DateTime.UtcNow.ToString("o"))
|
||||
],
|
||||
maxLength: 1000 * 10000);
|
||||
|
||||
_logger.LogInformation($"Published message {channel} {message}");
|
||||
|
|
@ -50,7 +54,7 @@ public class RedisPublisher : IEventPublisher
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"Error processing message: {ex.Message}, event id: {channel} {entry.Id}");
|
||||
_logger.LogError($"Error processing message: {ex.Message}, event id: {channel} {entry.Id}\r\n{ex}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ public class RedisSubscriber : IEventSubscriber
|
|||
foreach (var entry in entries)
|
||||
{
|
||||
_logger.LogInformation($"Consumer {Environment.MachineName} received: {channel} {entry.Values[0].Value}");
|
||||
await db.StreamAcknowledgeAsync(channel, group, entry.Id);
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -60,11 +61,7 @@ public class RedisSubscriber : IEventSubscriber
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError($"Error processing message: {ex.Message}, event id: {channel} {entry.Id}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
await db.StreamAcknowledgeAsync(channel, group, entry.Id);
|
||||
_logger.LogError($"Error processing message: {ex.Message}, event id: {channel} {entry.Id}\r\n{ex}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue