Skip to content

Commit

Permalink
Remove producer without options (#223)
Browse files Browse the repository at this point in the history
* Remove option-less producer as it seems to be useless
  • Loading branch information
alexeyzimarev authored Jun 13, 2023
1 parent a0e25a4 commit 27d152f
Show file tree
Hide file tree
Showing 29 changed files with 266 additions and 582 deletions.
101 changes: 67 additions & 34 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,51 +1,84 @@
root = true

[*]

indent_style = space
max_line_length = 160
brace_style = end_of_line

# IntelliJ IDEA properties
ij_any_block_brace_style = end_of_line

# Microsoft .NET properties
csharp_indent_braces = false
csharp_new_line_before_members_in_object_initializers = false
csharp_new_line_before_open_brace = control_blocks
csharp_preferred_modifier_order = protected, private, public, internal, file, new, override, abstract, virtual, sealed, readonly, static, extern, unsafe, volatile, async, required:suggestion
csharp_style_expression_bodied_accessors = true:suggestion
csharp_style_expression_bodied_constructors = false:none
csharp_style_expression_bodied_methods = true:none
csharp_style_expression_bodied_properties = true:suggestion
csharp_using_directive_placement = outside_namespace
csharp_style_var_for_built_in_types = true
csharp_sort_usings_with_system_first = true
csharp_default_private_modifier = implicit
csharp_default_internal_modifier = implicit
csharp_method_or_operator_body = expression_body
csharp_local_function_body = expression_body
csharp_constructor_or_destructor_body = expression_body
csharp_accessor_owner_body = expression_body
csharp_namespace_body = file_scoped
csharp_use_heuristics_for_body_style = false
csharp_force_attribute_style = separate
csharp_object_creation_when_type_evident = tartget_typed
csharp_object_creation_when_type_not_evident = tartget_typed
csharp_default_value_when_type_evident = default_literal
csharp_default_value_when_type_not_evident = default_literal
csharp_null_checking_pattern_style = not_null_pattern
csharp_remove_blank_lines_near_braces_in_declarations = true
csharp_blank_lines_after_file_scoped_namespace_directive = 1
csharp_blank_lines_around_type = 1
csharp_blank_lines_inside_type = 0
csharp_blank_lines_around_single_line_auto_property = 0
csharp_blank_lines_around_invocable = 1
csharp_remove_blank_lines_near_braces_in_code = true
csharp_blank_lines_before_control_transfer_statements = 1
csharp_space_around_binary_operator = true
csharp_space_after_unary_operator = false
csharp_indent_nested_usings_stmt = true
csharp_int_align_parameters = true
csharp_int_align_variables = true
csharp_int_align_assignments = true
csharp_int_align_nested_ternary = true
csharp_int_align_invocations = false
csharp_int_align_comments = true
csharp_int_align_switch_sections = true
csharp_int_align_switch_expressions = true
csharp_builtin_type_reference_style = use_keyword
csharp_place_expr_method_on_single_line = if_owner_is_single_line
csharp_place_expr_property_on_single_line = if_owner_is_single_line
csharp_place_expr_accessor_on_single_line = if_owner_is_single_line
csharp_wrap_before_arrow_with_expressions = true
csharp_wrap_before_first_type_parameter_constraint = true
csharp_wrap_multiple_type_parameter_constraints_style = chop_if_long
csharp_wrap_before_type_parameter_langle = true
csharp_wrap_before_extends_colon = true
csharp_wrap_extends_list_style = chop_if_long
csharp_keep_existing_arrangement = false
csharp_place_simple_blocks_on_single_line = true
csharp_place_simple_method_on_single_line = false
csharp_max_enum_members_on_line = 0
csharp_new_line_before_catch = false
csharp_new_line_before_finally = false
csharp_place_simple_case_statement_on_same_line = true
csharp_wrap_before_ternary_opsigns = true
csharp_empty_block_style = together
csharp_wrap_parameters_style = chop_if_long
csharp_max_formal_parameters_on_line = 5
csharp_place_constructor_initializer_on_same_line = false

# ReSharper properties
resharper_blank_lines_after_control_transfer_statements = 1
resharper_blank_lines_after_multiline_statements = 1
resharper_blank_lines_around_single_line_auto_property = 0
resharper_blank_lines_around_single_line_field = 0
resharper_blank_lines_before_control_transfer_statements = 0
resharper_csharp_align_multiline_binary_expressions_chain = true
resharper_csharp_blank_lines_around_single_line_field = 0
resharper_csharp_blank_lines_around_single_line_invocable = 1
resharper_csharp_empty_block_style = together
resharper_csharp_int_align_comments = true
resharper_csharp_max_line_length = 180
resharper_csharp_other_braces = end_of_line
resharper_csharp_wrap_after_declaration_lpar = true
resharper_csharp_wrap_arguments_style = chop_if_long
resharper_csharp_wrap_before_binary_opsign = true
resharper_csharp_wrap_before_declaration_rpar = true
resharper_csharp_wrap_parameters_style = chop_if_long
resharper_csharp_wrap_ternary_expr_style = chop_if_long
resharper_instance_members_qualify_declared_in =
resharper_int_align_assignments = true
resharper_int_align_fields = true
resharper_int_align_parameters = true
resharper_int_align_properties = true
resharper_max_attribute_length_for_same_line = 80
resharper_nested_ternary_style = expanded
resharper_outdent_binary_ops = true
resharper_place_expr_method_on_single_line = false
resharper_place_expr_property_on_single_line = true
resharper_place_field_attribute_on_same_line = false
resharper_place_simple_embedded_statement_on_same_line = true
resharper_space_within_single_line_array_initializer_braces = true
resharper_use_heuristics_for_body_style = true
resharper_wrap_object_and_collection_initializer_style = chop_if_long
resharper_wrap_parameters_style = wrap_if_long
resharper_wrap_ternary_expr_style = chop_if_long

file_header_template = Copyright (C) Ubiquitous AS. All rights reserved\nLicensed under the Apache License, Version 2.0.
file_header_template = Copyright (C) Ubiquitous AS.All rights reserved\nLicensed under the Apache License, Version 2.0.
12 changes: 0 additions & 12 deletions Eventuous.sln.DotSettings

This file was deleted.

45 changes: 13 additions & 32 deletions src/Core/src/Eventuous.Producers/BaseProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,21 @@ namespace Eventuous.Producers;

using Diagnostics;

public abstract class BaseProducer<TProduceOptions> : BaseProducer, IEventProducer<TProduceOptions> where TProduceOptions : class {
protected BaseProducer(ProducerTracingOptions? tracingOptions = null) : base(tracingOptions) { }

protected abstract Task ProduceMessages(StreamName stream, IEnumerable<ProducedMessage> messages, TProduceOptions? options, CancellationToken cancellationToken = default);

/// <inheritdoc />
public async Task Produce(StreamName stream, IEnumerable<ProducedMessage> messages, TProduceOptions? options, CancellationToken cancellationToken = default) {
var (activity, msgs) = ProducerActivity.Start(messages, DefaultTags);

if (activity is { IsAllDataRequested: true }) {
activity.SetTag(Messaging.Destination, stream);
}

await ProduceMessages(stream, msgs, options, cancellationToken).NoContext();

activity?.Dispose();
}

/// <inheritdoc />
protected override Task ProduceMessages(StreamName stream, IEnumerable<ProducedMessage> messages, CancellationToken cancellationToken = default)
=> ProduceMessages(stream, messages, null, cancellationToken);
}

public abstract class BaseProducer : IEventProducer {
protected KeyValuePair<string, object?>[] DefaultTags { get; }

public abstract class BaseProducer<TProduceOptions> : IEventProducer<TProduceOptions> where TProduceOptions : class {
protected BaseProducer(ProducerTracingOptions? tracingOptions = null) {
var options = tracingOptions ?? new ProducerTracingOptions();
DefaultTags = options.AllTags.Concat(EventuousDiagnostics.Tags).ToArray();
}

protected abstract Task ProduceMessages(StreamName stream, IEnumerable<ProducedMessage> messages, CancellationToken cancellationToken = default);
protected KeyValuePair<string, object?>[] DefaultTags { get; }

public async Task Produce(StreamName stream, IEnumerable<ProducedMessage> messages, CancellationToken cancellationToken = default) {
protected abstract Task ProduceMessages(StreamName stream, IEnumerable<ProducedMessage> messages, TProduceOptions? options, CancellationToken cancellationToken = default);

public Task Produce(StreamName stream, IEnumerable<ProducedMessage> messages, CancellationToken cancellationToken = default)
=> Produce(stream, messages, null, cancellationToken);

/// <inheritdoc />
public async Task Produce(StreamName stream, IEnumerable<ProducedMessage> messages, TProduceOptions? options, CancellationToken cancellationToken = default) {
var messagesArray = messages.ToArray();
if (messagesArray.Length == 0) return;

Expand All @@ -53,15 +34,15 @@ public async Task Produce(StreamName stream, IEnumerable<ProducedMessage> messag
using var activity = traced.act;

if (activity is { IsAllDataRequested: true }) {
activity.SetTag(Messaging.Destination, stream);
activity.SetTag(TelemetryTags.Eventuous.Stream, stream);
activity.SetTag(Messaging.Destination, stream.ToString());
activity.SetTag(TelemetryTags.Eventuous.Stream, stream.ToString());
}

await ProduceMessages(stream, traced.msgs, cancellationToken).NoContext();
await ProduceMessages(stream, traced.msgs, options, cancellationToken).NoContext();

(Activity? act, ProducedMessage[] msgs) ForOne() {
var (act, producedMessage) = ProducerActivity.Start(messagesArray[0], DefaultTags);
return (act?.Start(), new[] { producedMessage });
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Eventuous.Producers.Diagnostics;

[EventSource(Name = $"{DiagnosticName.BaseName}.producer")]
public class ProducerEventSource<T> : EventSource where T : IEventProducer {
public class ProducerEventSource<T> : EventSource where T : class {
public static readonly ProducerEventSource<T> Log = new();

static readonly string ProducerName = typeof(T).Name;
Expand Down
1 change: 0 additions & 1 deletion src/Core/src/Eventuous.Producers/IEventProducer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace Eventuous.Producers;

[PublicAPI]
public interface IEventProducer {
/// <summary>
/// Produce a message wrapped in the <see cref="ProducedMessage"/>.
Expand Down
4 changes: 2 additions & 2 deletions src/Core/src/Eventuous.Producers/ProducedMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public ProducedMessage(
public AcknowledgeProduce? OnAck { get; init; }
public ReportFailedProduce? OnNack { get; init; }

public ValueTask Ack<T>() where T : IEventProducer {
public ValueTask Ack<T>() where T : class {
ProducerEventSource<T>.Log.ProduceAcknowledged(this);
return OnAck?.Invoke(this) ?? default;
}

public ValueTask Nack<T>(string message, Exception? exception) where T : IEventProducer {
public ValueTask Nack<T>(string message, Exception? exception) where T : class {
ProducerEventSource<T>.Log.ProduceNotAcknowledged(this, message, exception);
if (OnNack != null) return OnNack(this, message, exception);

Expand Down
4 changes: 2 additions & 2 deletions src/Core/src/Eventuous.Producers/ProducerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static Task Produce<TMessage>(
CancellationToken cancellationToken = default
) where TMessage : class {
var producedMessages =
message is IEnumerable<object> collection
Ensure.NotNull(message) is IEnumerable<object> collection
? ConvertMany(collection, metadata, additionalHeaders, onAck, onNack)
: ConvertOne(message, metadata, additionalHeaders, onAck, onNack);

Expand Down Expand Up @@ -58,7 +58,7 @@ public static Task Produce<TProduceOptions, TMessage>(
StreamName stream,
TMessage message,
Metadata? metadata,
TProduceOptions options,
TProduceOptions? options = null,
Metadata? additionalHeaders = null,
AcknowledgeProduce? onAck = null,
ReportFailedProduce? onNack = null,
Expand Down
2 changes: 1 addition & 1 deletion src/Core/src/Eventuous.Shared/Tools/Ensure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ public static string NotEmptyString(string? value, [CallerArgumentExpression("va
public static void IsTrue(bool condition, Func<Exception> getException) {
if (!condition) throw getException();
}
}
}
16 changes: 6 additions & 10 deletions src/Core/src/Eventuous.Shared/Tools/TaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,13 @@ static class TaskExtensions {

public static ConfiguredValueTaskAwaitable<T> NoContext<T>(this ValueTask<T> task) => task.ConfigureAwait(false);

public static ConfiguredCancelableAsyncEnumerable<T> NoContext<T>(
this IAsyncEnumerable<T> source,
CancellationToken cancellationToken
)
public static ConfiguredCancelableAsyncEnumerable<T> NoContext<T>(this IAsyncEnumerable<T> source, CancellationToken cancellationToken)
=> source.WithCancellation(cancellationToken).ConfigureAwait(false);

public static Task WhenAll(this IEnumerable<Task> tasks) => Task.WhenAll(tasks);

public static async Task WhenAll(this IEnumerable<ValueTask> tasks) {
var toAwait = tasks
.Where(valueTask => !valueTask.IsCompletedSuccessfully)
.Select(valueTask => valueTask.AsTask())
.ToList();
var toAwait = tasks.Where(valueTask => !valueTask.IsCompletedSuccessfully).Select(valueTask => valueTask.AsTask()).ToList();

if (toAwait.Count > 0) await Task.WhenAll(toAwait).NoContext();
}
Expand All @@ -36,8 +30,10 @@ public static async Task<IReadOnlyCollection<T>> WhenAll<T>(this IEnumerable<Val
var toAwait = new List<Task<T>>();

foreach (var valueTask in tasks) {
if (valueTask.IsCompletedSuccessfully) results.Add(valueTask.Result);
else toAwait.Add(valueTask.AsTask());
if (valueTask.IsCompletedSuccessfully)
results.Add(valueTask.Result);
else
toAwait.Add(valueTask.AsTask());
}

if (toAwait.Count == 0) return results;
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<LangVersion>11</LangVersion>
<LangVersion>preview</LangVersion>
<NoWarn>$(NoWarn);CS1591;CS0618;</NoWarn>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
12 changes: 6 additions & 6 deletions src/Gateway/src/Eventuous.Gateway/Eventuous.Gateway.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="$(CoreRoot)\Eventuous.Producers\Eventuous.Producers.csproj"/>
<ProjectReference Include="$(CoreRoot)\Eventuous.Subscriptions\Eventuous.Subscriptions.csproj"/>
<ProjectReference Include="$(CoreRoot)\Eventuous.Producers\Eventuous.Producers.csproj" />
<ProjectReference Include="$(CoreRoot)\Eventuous.Subscriptions\Eventuous.Subscriptions.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="Eventuous.Producers"/>
<Using Include="Eventuous.Subscriptions"/>
<Using Include="Eventuous.Producers" />
<Using Include="Eventuous.Subscriptions" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions"/>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(CoreRoot)\Eventuous.Shared\Tools\TaskExtensions.cs">
<Link>Tools\TaskExtensions.cs</Link>
</Compile>
<Using Include="Eventuous.Tools"/>
<Using Include="Eventuous.Tools" />
</ItemGroup>
</Project>
Loading

0 comments on commit 27d152f

Please sign in to comment.