Adding an ActionExceptionHandler for easier sync exception handling.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bc27728..df2a04a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,13 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [Unreleased]
+
+### Added
+
+- ExceptionHandler method on the IPulsarClientBuilder taking an Action\<ExceptionContext\> for easy sync exception handling
+
+
## [0.9.6] - 2020-10-15
### Fixed
diff --git a/README.md b/README.md
index 6eb410f..8bd71ca 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,10 @@
DotPulsar's API is strongly inspired by Apache Pulsar's official [Java client](https://pulsar.apache.org/docs/en/client-libraries-java/), but a 100% match is not a goal.
+## What's new?
+
+Have a look at the [changelog](CHANGELOG.md).
+
## Getting Started
Let's take a look at a "Hello world" example, where we first produce a message and then consume it.
@@ -94,11 +98,6 @@
Apache Pulsar has a [Slack instance](https://pulsar.apache.org/contact/) and there you'll find us in the #dev-dotpulsar channel. Just waiting for you to pop by :-)
-## Built With
-
-* [protobuf-net](https://github.com/mgravell/protobuf-net) - Provides simple access to fast and efficient "Protocol Buffers" serialization from .NET applications
-* [System.IO.Pipelines](https://www.nuget.org/packages/System.IO.Pipelines/) - Single producer single consumer byte buffer management
-
## Versioning
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/apache/pulsar-dotpulsar/tags).
diff --git a/src/DotPulsar/Abstractions/IPulsarClientBuilder.cs b/src/DotPulsar/Abstractions/IPulsarClientBuilder.cs
index 55cd63b..484a196 100644
--- a/src/DotPulsar/Abstractions/IPulsarClientBuilder.cs
+++ b/src/DotPulsar/Abstractions/IPulsarClientBuilder.cs
@@ -46,6 +46,11 @@
/// <summary>
/// Register a custom exception handler that will be invoked before the default exception handler.
/// </summary>
+ IPulsarClientBuilder ExceptionHandler(Action<ExceptionContext> exceptionHandler);
+
+ /// <summary>
+ /// Register a custom exception handler that will be invoked before the default exception handler.
+ /// </summary>
IPulsarClientBuilder ExceptionHandler(Func<ExceptionContext, ValueTask> exceptionHandler);
/// <summary>
diff --git a/src/DotPulsar/Internal/ActionExceptionHandler.cs b/src/DotPulsar/Internal/ActionExceptionHandler.cs
new file mode 100644
index 0000000..685b672
--- /dev/null
+++ b/src/DotPulsar/Internal/ActionExceptionHandler.cs
@@ -0,0 +1,20 @@
+namespace DotPulsar.Internal
+{
+ using DotPulsar.Abstractions;
+ using System;
+ using System.Threading.Tasks;
+
+ public sealed class ActionExceptionHandler : IHandleException
+ {
+ private readonly Action<ExceptionContext> _exceptionHandler;
+
+ public ActionExceptionHandler(Action<ExceptionContext> exceptionHandler)
+ => _exceptionHandler = exceptionHandler;
+
+ public ValueTask OnException(ExceptionContext exceptionContext)
+ {
+ _exceptionHandler(exceptionContext);
+ return new ValueTask();
+ }
+ }
+}
diff --git a/src/DotPulsar/Internal/PulsarClientBuilder.cs b/src/DotPulsar/Internal/PulsarClientBuilder.cs
index c00f1b0..88c1245 100644
--- a/src/DotPulsar/Internal/PulsarClientBuilder.cs
+++ b/src/DotPulsar/Internal/PulsarClientBuilder.cs
@@ -79,6 +79,12 @@
return this;
}
+ public IPulsarClientBuilder ExceptionHandler(Action<ExceptionContext> exceptionHandler)
+ {
+ _exceptionHandlers.Add(new ActionExceptionHandler(exceptionHandler));
+ return this;
+ }
+
public IPulsarClientBuilder ExceptionHandler(Func<ExceptionContext, ValueTask> exceptionHandler)
{
_exceptionHandlers.Add(new FuncExceptionHandler(exceptionHandler));