Skip to content

Commit

Permalink
Documentations and licensing
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutomi committed Sep 18, 2024
1 parent c1401c2 commit 9aadaa5
Show file tree
Hide file tree
Showing 53 changed files with 1,537 additions and 104 deletions.
16 changes: 16 additions & 0 deletions Deveel.Events.licenseheader
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extensions: designer.cs generated.cs
extensions: .cs .cpp .h
//
// Copyright 2023-2024 Antonello Provenzano
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\Deveel.Events.Publisher\Deveel.Events.Publisher.csproj" />
<ProjectReference Include="..\..\src\Deveel.Events.Schema\Deveel.Events.Schema.csproj" />
<ProjectReference Include="..\..\src\Deveel.Events.TestPublisher\Deveel.Events.TestPublisher.csproj" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/DeveelEventsBenchmarks/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

using DeveelEventsBenchmarks;

var summary = BenchmarkRunner.Run<PublishBenchmarks>();
BenchmarkRunner.Run<PublishBenchmarks>();
60 changes: 60 additions & 0 deletions benchmarks/DeveelEventsBenchmarks/SchemaGenBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;

using Deveel.Events;

using System.ComponentModel.DataAnnotations;

namespace DeveelEventsBenchmarks
{
[SimpleJob(RuntimeMoniker.Net60)]
[SimpleJob(RuntimeMoniker.Net70)]
[SimpleJob(RuntimeMoniker.Net80)]
[MemoryDiagnoser]
[RyuJitX64Job, RyuJitX86Job]
public class SchemaGenBenchmarks
{
[Benchmark]
public static void CreateSchemaFromData()
{
EventSchema.FromDataType<PersonCreated>();
}

[Benchmark]
public static void ManualSchemaCreation()
{
var schema = new EventSchema("person.created", "2.0", "contentType")
{
Description = "A new person was created",
};

var nameProperty = new EventProperty("name", "string", "1.0")
{
Description = "The name of the person"
};
nameProperty.Constraints.Add(new PropertyRequiredConstraint());

var ageProperty = new EventProperty("age", "int", "1.2")
{
Description = "The age of the person"
};
ageProperty.Constraints.Add(new RangeConstraint<int>(0, 110));

schema.Properties.Add(nameProperty);
schema.Properties.Add(ageProperty);
}

[Event("person.created", "2.0", Description = "A new person was created")]
[EventAttributes("contentType", "application/json")]
class PersonCreated
{
[EventProperty("name", "1.0", Description = "The name of the person")]
[Required]
public string Name { get; set; }

[EventProperty("age", "1.2", Description = "The age of the person")]
[Range(0, 110)]
public int? Age { get; set; }
}
}
}
17 changes: 16 additions & 1 deletion src/Deveel.Events.Model/Events/EventAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
using System;
//
// Copyright 2023-2024 Antonello Provenzano
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;

namespace Deveel.Events {
/// <summary>
Expand Down
17 changes: 16 additions & 1 deletion src/Deveel.Events.Model/Events/EventAttributesAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
namespace Deveel.Events {
//
// Copyright 2023-2024 Antonello Provenzano
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Deveel.Events {
/// <summary>
/// An attribute that can be used to describe additional attributes
/// (such as metadata) that can be attached to an event
Expand Down
17 changes: 16 additions & 1 deletion src/Deveel.Events.Model/Events/EventPropertyAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
namespace Deveel.Events {
//
// Copyright 2023-2024 Antonello Provenzano
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Deveel.Events {
/// <summary>
/// An attribute that is used to mark a property of a
/// type as a property of the payload of the event.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
using Microsoft.Extensions.DependencyInjection;
//
// Copyright 2023-2024 Antonello Provenzano
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
using Azure.Messaging.ServiceBus;
//
// Copyright 2023-2024 Antonello Provenzano
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using Azure.Messaging.ServiceBus;

namespace Deveel.Events {
public interface IServiceBusClientFactory {
/// <summary>
/// A service used to create instances of <see cref="ServiceBusClient"/>
/// for communication with Azure Service Bus.
/// </summary>
public interface IServiceBusClientFactory {
/// <summary>
/// Creates a new instance of <see cref="ServiceBusClient"/>
/// from the given connection string and options.
/// </summary>
/// <param name="connectionString">
/// The connection string to the Azure Service Bus.
/// </param>
/// <param name="options">
/// The options to use when creating the client.
/// </param>
/// <returns>
/// Returns a new instance of <see cref="ServiceBusClient"/>
/// that can be used to communicate with the Azure Service Bus.
/// </returns>
ServiceBusClient CreateClient(string connectionString, ServiceBusClientOptions options);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
using Microsoft.Extensions.Logging;
//
// Copyright 2023-2024 Antonello Provenzano
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using Microsoft.Extensions.Logging;

namespace Deveel.Events {
static partial class LoggerExtensions {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
using Azure.Messaging.ServiceBus;
//
// Copyright 2023-2024 Antonello Provenzano
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using Azure.Messaging.ServiceBus;

namespace Deveel.Events {
class ServiceBusClientFactory : IServiceBusClientFactory {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
using System.Runtime.Serialization;
//
// Copyright 2023-2024 Antonello Provenzano
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Runtime.Serialization;

using Azure.Messaging.ServiceBus;

Expand All @@ -9,15 +24,35 @@
using Microsoft.Extensions.Options;

namespace Deveel.Events {
public sealed class ServiceBusEventPublishChannel : IEventPublishChannel, IAsyncDisposable, IDisposable {
/// <summary>
/// A channel that publishes events to an Azure Service Bus queue.
/// </summary>
public sealed class ServiceBusEventPublishChannel : IEventPublishChannel, IAsyncDisposable, IDisposable {
private ServiceBusSender? sender;
private ServiceBusClient? client;
private readonly ServiceBusMessageFactory messageCreator;
private readonly ILogger logger;

private bool disposed;

public ServiceBusEventPublishChannel(
/// <summary>
/// Creates a new instance of the channel,
/// using the specified options, client factory
/// and message creator.
/// </summary>
/// <param name="options">
/// The options to configure the channel.
/// </param>
/// <param name="clientFactory">
/// A factory to create the client to the Azure Service Bus.
/// </param>
/// <param name="messageCreator">
/// The factory to create the message to send to the queue.
/// </param>
/// <param name="logger">
/// A logger to record the operations of the channel.
/// </param>
public ServiceBusEventPublishChannel(
IOptions<ServiceBusEventPublishChannelOptions> options,
IServiceBusClientFactory clientFactory,
ServiceBusMessageFactory messageCreator,
Expand Down Expand Up @@ -49,7 +84,8 @@ private void ThrowIfDisposed() {
throw new ObjectDisposedException(nameof(ServiceBusEventPublishChannel));
}

public async Task PublishAsync(CloudEvent @event, CancellationToken cancellationToken = default) {
/// <inheritdoc />
public async Task PublishAsync(CloudEvent @event, CancellationToken cancellationToken = default) {
ThrowIfDisposed();
cancellationToken.ThrowIfCancellationRequested();

Expand All @@ -72,14 +108,16 @@ public async Task PublishAsync(CloudEvent @event, CancellationToken cancellation

}

public void Dispose() {
/// <inheritdoc />
public void Dispose() {
if (disposed)
return;

DisposeAsyncCore().GetAwaiter().GetResult();
}

public async ValueTask DisposeAsync() {
/// <inheritdoc />
public async ValueTask DisposeAsync() {
if (disposed)
return;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
using Azure.Messaging.ServiceBus;
//
// Copyright 2023-2024 Antonello Provenzano
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using Azure.Messaging.ServiceBus;

namespace Deveel.Events {
public class ServiceBusEventPublishChannelOptions {
/// <summary>
/// The options for a channel that publishes events
/// to an Azure Service Bus.
/// </summary>
public class ServiceBusEventPublishChannelOptions {
/// <summary>
/// Gets or sets the connection string to the Azure Service Bus
/// instance that is used to publish the events.
/// </summary>
public string ConnectionString { get; set; }

/// <summary>
/// Gets or sets the name of the queue in the Azure Service Bus
/// where the events are published.
/// </summary>
public string QueueName { get; set; }

/// <summary>
/// Gets or sets the options for the client that connects to the
/// Azure Service Bus.
/// </summary>
public ServiceBusClientOptions ClientOptions { get; set; } = new ServiceBusClientOptions();
}
}
Loading

0 comments on commit 9aadaa5

Please sign in to comment.