try to refactor Kafka and add supports for RabbitMQ ...
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using System.Linq;
|
||||
using xCommons.Extensions;
|
||||
using xEventService.Configuration;
|
||||
using xEventService.Constants;
|
||||
using xEventService.Models;
|
||||
using xExceptions.Constants;
|
||||
|
||||
namespace xEventService.Extensions
|
||||
{
|
||||
@@ -44,6 +46,37 @@ namespace xEventService.Extensions
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate RabbitMQ Exchange Type ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsValid(this XRabbitMQExchangeType source)
|
||||
{
|
||||
//
|
||||
var result = source != XRabbitMQExchangeType.None;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate RabbitMQ Configuration ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsValid(this XRabbitMQOptions source)
|
||||
{
|
||||
//
|
||||
var result =
|
||||
!source.IsNullOrDefault() &&
|
||||
!source.Exchange.IsNullOrEmpty() &&
|
||||
!source.ExchangeType.IsValid();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate an Event Message ...
|
||||
/// </summary>
|
||||
@@ -77,5 +110,110 @@ namespace xEventService.Extensions
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate an Array is Wildcard passed or not ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsAllowedWildcard(this string[] source)
|
||||
{
|
||||
//
|
||||
var result =
|
||||
source is not null &&
|
||||
source.Length == 1 &&
|
||||
source.Any(s =>
|
||||
s == XEventServiceConstants.XWildcard);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validate a Collection is Valid for Kafka Consumer ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsAllowedCollection(
|
||||
this string[] source
|
||||
)
|
||||
{
|
||||
//
|
||||
var result = source.HasChild();
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse Url and Extract Host address ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetRabbitMQHost(this XEventServiceConfiguration source)
|
||||
{
|
||||
//
|
||||
var result = string.Empty;
|
||||
|
||||
//
|
||||
if (!source.IsValid())
|
||||
{
|
||||
XException.InvalidConfiguration.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var parts = source.Url.Split(':');
|
||||
if (parts.Length != 2)
|
||||
{
|
||||
XException.InvalidConfiguration.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
result = parts[0];
|
||||
if (result.IsNullOrEmpty() ||
|
||||
!result.IsValidUrl()
|
||||
)
|
||||
{
|
||||
XException.InvalidConfiguration.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parse Url and Extract Port Number ...
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetRabbitMQPort(this XEventServiceConfiguration source)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (!source.IsValid())
|
||||
{
|
||||
XException.InvalidConfiguration.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
var parts = source.Url.Split(':');
|
||||
if (parts.Length != 2)
|
||||
{
|
||||
XException.InvalidConfiguration.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
// Try Parse Port as Integer ...
|
||||
int.TryParse(parts[1], out result);
|
||||
if (result <= 0)
|
||||
{
|
||||
XException.InvalidConfiguration.Throw();
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user