-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Many updates and errors solved (#53)
* Added missing file * #52: fix management of serialization * #52: fix some errors, code cleanup and added new options * #22: update to KNet 2.0.1
- Loading branch information
1 parent
6ed45d1
commit d240120
Showing
15 changed files
with
288 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
/* | ||
* Copyright 2022 MASES s.r.l. | ||
* | ||
* 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. | ||
* | ||
* Refer to LICENSE for more information. | ||
*/ | ||
|
||
using MASES.KNet.Common; | ||
using MASES.KNet.Producer; | ||
using MASES.KNet.Streams; | ||
|
||
namespace MASES.EntityFrameworkCore.KNet.Infrastructure; | ||
|
||
/// <summary> | ||
/// Allows Kafka specific configuration to be performed on <see cref="DbContext" />. | ||
/// </summary> | ||
public class KafkaDbContext : DbContext | ||
{ | ||
/// <summary> | ||
/// The bootstrap servers of the Apache Kafka cluster | ||
/// </summary> | ||
public string? BootstrapServers { get; set; } | ||
/// <summary> | ||
/// The application id | ||
/// </summary> | ||
public string ApplicationId { get; set; } = Guid.NewGuid().ToString(); | ||
/// <summary> | ||
/// Database name | ||
/// </summary> | ||
public string? DbName { get; set; } | ||
/// <summary> | ||
/// Database number of partitions | ||
/// </summary> | ||
public int DefaultNumPartitions { get; set; } = 10; | ||
/// <summary> | ||
/// Database replication factor | ||
/// </summary> | ||
public short DefaultReplicationFactor { get; set; } = 1; | ||
/// <summary> | ||
/// Use persistent storage | ||
/// </summary> | ||
public bool UsePersistentStorage { get; set; } = false; | ||
/// <summary> | ||
/// Use a producer for each Entity | ||
/// </summary> | ||
public bool UseProducerByEntity { get; set; } = false; | ||
|
||
public ProducerConfigBuilder? ProducerConfigBuilder { get; set; } | ||
|
||
public StreamsConfigBuilder? StreamsConfigBuilder { get; set; } | ||
|
||
public TopicConfigBuilder? TopicConfigBuilder { get; set; } | ||
|
||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) | ||
{ | ||
if (BootstrapServers == null) | ||
{ | ||
throw new ArgumentNullException(nameof(BootstrapServers)); | ||
} | ||
|
||
if (DbName == null) throw new ArgumentNullException(nameof(DbName)); | ||
|
||
optionsBuilder.UseKafkaDatabase(ApplicationId, DbName, BootstrapServers, (o) => | ||
{ | ||
o.StreamsConfig(StreamsConfigBuilder??o.EmptyStreamsConfigBuilder).WithDefaultNumPartitions(DefaultNumPartitions); | ||
o.WithUsePersistentStorage(UsePersistentStorage); | ||
o.WithProducerByEntity(UseProducerByEntity); | ||
o.WithDefaultReplicationFactor(DefaultReplicationFactor); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.