Skip to content

Commit

Permalink
Cleaning up and optimizing methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkCiliaVincenti committed Aug 9, 2024
1 parent 8ef13b7 commit 896f128
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 421 deletions.
45 changes: 6 additions & 39 deletions src/EasyCaching.Core/EasyCachingAbstractBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,53 +28,31 @@ public abstract class EasyCachingAbstractBus : IEasyCachingBus
public void Publish(string topic, EasyCachingMessage message)
{
var operationId = s_diagnosticListener.WritePublishMessageBefore(new BeforePublishMessageRequestEventData(topic, message));
Exception e = null;
try
{
BasePublish(topic, message);
}
catch (Exception ex)
{
e = ex;
s_diagnosticListener.WritePublishMessageError(operationId, ex);
throw;
}
finally
{
if (e != null)
{
s_diagnosticListener.WritePublishMessageError(operationId, e);
}
else
{
s_diagnosticListener.WritePublishMessageAfter(operationId);
}
}
s_diagnosticListener.WritePublishMessageAfter(operationId);
}

public async Task PublishAsync(string topic, EasyCachingMessage message, CancellationToken cancellationToken = default(CancellationToken))
{
var operationId = s_diagnosticListener.WritePublishMessageBefore(new BeforePublishMessageRequestEventData(topic, message));
Exception e = null;
try
{
await BasePublishAsync(topic, message, cancellationToken);
}
catch (Exception ex)
{
e = ex;
s_diagnosticListener.WritePublishMessageError(operationId, ex);
throw;
}
finally
{
if (e != null)
{
s_diagnosticListener.WritePublishMessageError(operationId, e);
}
else
{
s_diagnosticListener.WritePublishMessageAfter(operationId);
}
}
s_diagnosticListener.WritePublishMessageAfter(operationId);
}

public void Subscribe(string topic, Action<EasyCachingMessage> action, Action reconnectAction)
Expand All @@ -94,27 +72,16 @@ public void Subscribe(string topic, Action<EasyCachingMessage> action, Action re
public virtual void BaseOnMessage(EasyCachingMessage message)
{
var operationId = s_diagnosticListener.WriteSubscribeMessageBefore(new BeforeSubscribeMessageRequestEventData(message));
Exception e = null;
try
{
_handler?.Invoke(message);
}
catch (Exception ex)
{
e = ex;
s_diagnosticListener.WritePublishMessageError(operationId, ex);
throw;
}
finally
{
if (e != null)
{
s_diagnosticListener.WritePublishMessageError(operationId, e);
}
else
{
s_diagnosticListener.WritePublishMessageAfter(operationId);
}
}
s_diagnosticListener.WritePublishMessageAfter(operationId);
}

public virtual void BaseOnReconnect()
Expand Down
Loading

0 comments on commit 896f128

Please sign in to comment.