<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mario Mastrodicasa</title>
    <description>The latest articles on DEV Community by Mario Mastrodicasa (@mario_mastrodicasa).</description>
    <link>https://dev.to/mario_mastrodicasa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4256033%2F955cc07f-ee29-4108-b5ae-7858b6a7cad5.png</url>
      <title>DEV Community: Mario Mastrodicasa</title>
      <link>https://dev.to/mario_mastrodicasa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mario_mastrodicasa"/>
    <language>en</language>
    <item>
      <title>Entity Framework Core provider for Apache Kafka - How it works and use cases</title>
      <dc:creator>Mario Mastrodicasa</dc:creator>
      <pubDate>Thu, 26 Nov 2026 00:24:56 +0000</pubDate>
      <link>https://dev.to/mario_mastrodicasa/entity-framework-core-provider-for-apache-kafka-how-it-works-and-use-cases-1j66</link>
      <guid>https://dev.to/mario_mastrodicasa/entity-framework-core-provider-for-apache-kafka-how-it-works-and-use-cases-1j66</guid>
      <description>&lt;p&gt;Upon first major release of &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;&lt;strong&gt;Entity Framework Core&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;provider for&lt;/strong&gt; &lt;a href="https://kafka.apache.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Apache Kafka&lt;/strong&gt;&lt;/a&gt; I try to describe how it can be used in some &lt;a href="https://kefcore.masesgroup.com/articles/usecases.html" rel="noopener noreferrer"&gt;operative conditions&lt;/a&gt; to unleash the power of Apache Kafka. However it is important to describe how it works to better understand some other concepts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt; : In the following chapters sometime it is used the term back-end and sometime Apache Kafka cluster: they shall be considered the same thing int the &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;&lt;strong&gt;Entity Framework Core&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;provider for&lt;/strong&gt; &lt;a href="https://kafka.apache.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Apache Kafka&lt;/strong&gt;&lt;/a&gt; context.&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic concepts
&lt;/h3&gt;

&lt;p&gt;Here below an image describing simple concepts:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fndcfkvnkcx3a96gura57.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fndcfkvnkcx3a96gura57.png" alt="Kafka image from https://www.qlik.com/us/streaming-data/apache-kafka" width="800" height="594"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Kafka image from &lt;a href="https://www.qlik.com/us/streaming-data/apache-kafka" rel="noopener noreferrer"&gt;https://www.qlik.com/us/streaming-data/apache-kafka&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Simplifying, there are three active elements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Topics&lt;/strong&gt; : storage of the records (the data), they are hosted in the Apache Kafka cluster and can be partitioned&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Producers&lt;/strong&gt; : entities producing records to be stored in one or more topics&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consumers&lt;/strong&gt; : entities receiving records from the topics&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When a producer send a record to Apache Kafka cluster, the record will be sent to the consumers subscribed to the topics the producer is producing on: this is a classic pub-sub pattern. Apache Kafka cluster adds the ability to store this information within the topic the producer has produced on, this feature guarantee that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;an application consuming from the Apache Kafka cluster can hear only latest changes or reposition to a specific record in the past and start from that point to receive data&lt;/li&gt;
&lt;li&gt;the standard way to consume from Apache Kafka cluster is to start from the end (latest available record) or start from the beginning (first available record)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  How &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt; provider for &lt;a href="https://kafka.apache.org/" rel="noopener noreferrer"&gt;Apache Kafka&lt;/a&gt; works
&lt;/h3&gt;

&lt;p&gt;An application based on &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;&lt;strong&gt;Entity Framework Core&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;provider for&lt;/strong&gt; &lt;a href="https://kafka.apache.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Apache Kafka&lt;/strong&gt;&lt;/a&gt; is both a producer and a consumer at the same time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;when an entity is created/updated/deleted (e.g. calling &lt;a href="https://learn.microsoft.com/en-us/ef/core/saving/basic" rel="noopener noreferrer"&gt;SaveChanges&lt;/a&gt;) the provider will invoke the right producer to store a new record in the right topic of the Apache Kafka cluster&lt;/li&gt;
&lt;li&gt;then the consumer subscribed will be informed about this new record and will store it back: this seems not useful till now, but it will be more clear later&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Apache Kafka cluster becomes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;a central routing for data changes in multiple &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt; based applications;&lt;/li&gt;
&lt;li&gt;a reliable storage because, when the application restarts, the data stored in the topics will be read back from the consumers so the local state will be aligned to the latest available.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Apache Kafka comes with &lt;a href="https://kafka.apache.org/documentation/#compaction" rel="noopener noreferrer"&gt;topic compaction&lt;/a&gt; feature: this feature optimizes the point 2. &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;&lt;strong&gt;Entity Framework Core&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;provider for&lt;/strong&gt; &lt;a href="https://kafka.apache.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Apache Kafka&lt;/strong&gt;&lt;/a&gt; is interested to store only the latest state of the entity and not the changes. Using the &lt;a href="https://kafka.apache.org/documentation/#compaction" rel="noopener noreferrer"&gt;topic compaction&lt;/a&gt;, the combination of producer, consumer and Apache Kafka cluster can apply the CRUD operations on data:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Create&lt;/strong&gt; : a producer stores a new record with its unique key&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read&lt;/strong&gt; : a consumer retrieves records from topic&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Update&lt;/strong&gt; : when a producer stores a new record with a previously stored unique key, the Apache Kafka cluster will discard the old records&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Delete&lt;/strong&gt; : when a producer stores a new record with a value set to null, and a previously stored unique key, the Apache Kafka cluster will delete all records with that unique key&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All CRUD operations are helped, behind the scene, from &lt;a href="https://github.com/masesgroup/KNet/blob/master/src/net/KNet/Specific/Replicator/KNetCompactedReplicator.cs" rel="noopener noreferrer"&gt;KNetCompactedReplicator&lt;/a&gt; or &lt;a href="https://github.com/masesgroup/KNet/blob/master/src/net/KNet/Specific/Producer/KNetProducer.cs" rel="noopener noreferrer"&gt;KNetProducer&lt;/a&gt;/ &lt;a href="https://kafka.apache.org/documentation/streams/" rel="noopener noreferrer"&gt;Apache Kafka Streams&lt;/a&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  First-level cache
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://github.com/masesgroup/KNet/blob/master/src/net/KNet/Specific/Replicator/KNetCompactedReplicator.cs" rel="noopener noreferrer"&gt;KNetCompactedReplicator&lt;/a&gt; or &lt;a href="https://kafka.apache.org/documentation/streams/" rel="noopener noreferrer"&gt;Apache Kafka Streams&lt;/a&gt; act as first-level cache of &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt;: &lt;strong&gt;data coming from the Apache Kafka cluster update their in-memory image while the system is running&lt;/strong&gt;. The behavior is intrinsic and does not need any extra call to the back-end.&lt;/p&gt;
&lt;h4&gt;
  
  
  Data storage
&lt;/h4&gt;

&lt;p&gt;Apache Kafka stores the information using records. It is important to convert entities in something usable from Apache Kafka. The conversion is done using serializers that converts the Entities (data in the model) into Apache Kafka records and viceversa: see &lt;a href="https://kefcore.masesgroup.com/KEFCore/articles/serialization.html" rel="noopener noreferrer"&gt;serialization chapter&lt;/a&gt; for more info.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt; provider for &lt;a href="https://kafka.apache.org/" rel="noopener noreferrer"&gt;Apache Kafka&lt;/a&gt; compared to other providers
&lt;/h3&gt;

&lt;p&gt;In the previous chapter was described how &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;&lt;strong&gt;Entity Framework Core&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;provider for&lt;/strong&gt; &lt;a href="https://kafka.apache.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Apache Kafka&lt;/strong&gt;&lt;/a&gt; permits to reproduce the CRUD operations. Starting from the model defined in the code, the data are stored in the topics and each topic can be seen as a table of a database filled in with the same data. From the point of view of an application, the use of &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt; provider for &lt;a href="https://kafka.apache.org/" rel="noopener noreferrer"&gt;Apache Kafka&lt;/a&gt; is similar to the use of the InMemory provider.&lt;/p&gt;
&lt;h4&gt;
  
  
  A note on &lt;a href="https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations" rel="noopener noreferrer"&gt;migrations&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;The current version of &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;&lt;strong&gt;Entity Framework Core&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;provider for&lt;/strong&gt; &lt;a href="https://kafka.apache.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Apache Kafka&lt;/strong&gt;&lt;/a&gt; does not support &lt;a href="https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations" rel="noopener noreferrer"&gt;migrations&lt;/a&gt; explicitly.&lt;/p&gt;
&lt;h4&gt;
  
  
  Use case: database
&lt;/h4&gt;

&lt;p&gt;An use case can be coupled to a standard usage of &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt;, the same case when &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt; is used with database providers. In &lt;a href="https://kefcore.masesgroup.com/articles/gettingstarted.html" rel="noopener noreferrer"&gt;getting started&lt;/a&gt; is proposed a simple example following the online documentation. In the example the data within the model are stored in multiple Apache Kafka topics, each topic is correlated to the &lt;a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbset-1" rel="noopener noreferrer"&gt;DbSet&lt;/a&gt; described from the &lt;a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbcontext" rel="noopener noreferrer"&gt;DbContext&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The constraints are managed using &lt;a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbcontext.onmodelcreating" rel="noopener noreferrer"&gt;OnModelCreating&lt;/a&gt; of &lt;a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbcontext" rel="noopener noreferrer"&gt;DbContext&lt;/a&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Use case: user data in topics
&lt;/h4&gt;

&lt;p&gt;Changing the mind about model, another use case can be coupled on how an &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt; model can be used; since the data within the model are stored in multiple Apache Kafka topics, if the model is written in a way it describes the data to be stored within the topics it is possible to define an uncorrelated model containing the data of interest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ModelContext&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;KafkaDbContext&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;DbSet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;FirstData&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;FirstDatas&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;DbSet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;SecondData&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;SecondDatas&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FirstData&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;ItemId&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;Data&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SecondData&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;ItemId&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;Data&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then using standard APIs of &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt;, an user interacting with &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt; can stores, or retrieves, data without any, or limited, knowledge of Apache Kafka.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt; provider for &lt;a href="https://kafka.apache.org/" rel="noopener noreferrer"&gt;Apache Kafka&lt;/a&gt; features not available in other providers
&lt;/h3&gt;

&lt;p&gt;Here a list of features &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;&lt;strong&gt;Entity Framework Core&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;provider for&lt;/strong&gt; &lt;a href="https://kafka.apache.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Apache Kafka&lt;/strong&gt;&lt;/a&gt; gives to its user and useful in some use cases. The features below are strictly correlated with the consumers receiving back the record from Apache Kafka cluster described above.&lt;/p&gt;

&lt;h4&gt;
  
  
  Distributed cache
&lt;/h4&gt;

&lt;p&gt;In the previous chapter was stated that consumers align the application data to the last topics information. The alignment is managed from &lt;a href="https://github.com/masesgroup/KNet/blob/master/src/net/KNet/Specific/Replicator/KNetCompactedReplicator.cs" rel="noopener noreferrer"&gt;KNetCompactedReplicator&lt;/a&gt; and/or &lt;a href="https://kafka.apache.org/documentation/streams/" rel="noopener noreferrer"&gt;Apache Kafka Streams&lt;/a&gt;, everything is driven from the Apache Kafka back-end. Considering two, or more, applications, sharing the same model and configuration, they always align to the latest state of the topics involved. This implies that, virtually, there is a distributed cache between the applications and the Apache Kafka back-end:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Apache Kafka stores physically the cache (shared state) within the topics and routes changes to the subscribed applications&lt;/li&gt;
&lt;li&gt;Applications use latest cache version (local state) received from Apache Kafka back-end&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If an application restarts it will be able to retrieve latest data (latest cache) and aligns to the shared state.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv32atcblt3706hbvbq5x.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv32atcblt3706hbvbq5x.gif" alt="Distributed cache" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Distributed cache&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Changing the mind a model is written it is possible to define a set of classes which acts as storage for data we want to use as a cache. It is possible to build a new model like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CachingContext&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;KafkaDbContext&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;DbSet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Item&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Items&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Item&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;ItemId&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;Data&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sharing it between multiple applications and allocating the CachingContext in each application, the cache is shared and the same data are available.&lt;/p&gt;

&lt;h4&gt;
  
  
  Events
&lt;/h4&gt;

&lt;p&gt;Generally, an application based on &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt;, executes queries to the back-end to store, or retrieve, information on demand. The alignment (record consumed) can be considered a change event: so any change in the backend produces an event used in different mode:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mainly these change events are used from &lt;a href="https://github.com/masesgroup/KNet/blob/master/src/net/KNet/Specific/Replicator/KNetCompactedReplicator.cs" rel="noopener noreferrer"&gt;KNetCompactedReplicator&lt;/a&gt; and/or &lt;a href="https://kafka.apache.org/documentation/streams/" rel="noopener noreferrer"&gt;Apache Kafka Streams&lt;/a&gt; to align the local state;&lt;/li&gt;
&lt;li&gt;Moreover &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;&lt;strong&gt;Entity Framework Core&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;provider for&lt;/strong&gt; &lt;a href="https://kafka.apache.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Apache Kafka&lt;/strong&gt;&lt;/a&gt; can inform, using callbacks and at zero cost, the registered application about these events.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The application can use the reported events in many modes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;execute a query&lt;/li&gt;
&lt;li&gt;write something to disk&lt;/li&gt;
&lt;li&gt;execute a REST call&lt;/li&gt;
&lt;li&gt;and so on&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbdppv1jzp49beghl4v6k.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbdppv1jzp49beghl4v6k.gif" alt="Events" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Events&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;IMPORTANT NOTE&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;: the events are raised from external threads and this can lead to&lt;/em&gt; &lt;a href="https://learn.microsoft.com/en-us/ef/core/dbcontext-configuration/#avoiding-dbcontext-threading-issues" rel="noopener noreferrer"&gt;&lt;em&gt;concurrent exceptions&lt;/em&gt;&lt;/a&gt; &lt;em&gt;if the&lt;/em&gt; &lt;em&gt;KafkaDbContext is used to retrieve information.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Continuing from the previous use case, using the events reported from &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;&lt;strong&gt;Entity Framework Core&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;provider for&lt;/strong&gt; &lt;a href="https://kafka.apache.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Apache Kafka&lt;/strong&gt;&lt;/a&gt; it is possible to write a reactive application. When a change event is triggered the application can react to it and take an action.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzeqrft4trog68kgj5jt0.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzeqrft4trog68kgj5jt0.gif" alt="Triggered distributed cache" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Triggered distributed cache&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The triggered distributed cache can be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;seen as a &lt;a href="https://redis.io/" rel="noopener noreferrer"&gt;Redis&lt;/a&gt; backend;&lt;/li&gt;
&lt;li&gt;used side-by-side with &lt;a href="https://learn.microsoft.com/it-it/aspnet/signalr/overview/getting-started/introduction-to-signalr" rel="noopener noreferrer"&gt;SignalR&lt;/a&gt;: combining &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;&lt;strong&gt;Entity Framework Core&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;provider for&lt;/strong&gt; &lt;a href="https://kafka.apache.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Apache Kafka&lt;/strong&gt;&lt;/a&gt; and &lt;a href="https://learn.microsoft.com/it-it/aspnet/signalr/overview/getting-started/introduction-to-signalr" rel="noopener noreferrer"&gt;SignalR&lt;/a&gt; in an application, subscribing to the change events, it is possible to feed the connected applications to &lt;a href="https://learn.microsoft.com/it-it/aspnet/signalr/overview/getting-started/introduction-to-signalr" rel="noopener noreferrer"&gt;SignalR&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Applications not based on &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Till now was spoken about applications based on &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt;, however this provider can be used to feed applications not based on &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt;. &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;&lt;strong&gt;Entity Framework Core&lt;/strong&gt;&lt;/a&gt; &lt;strong&gt;provider for&lt;/strong&gt; &lt;a href="https://kafka.apache.org/" rel="noopener noreferrer"&gt;&lt;strong&gt;Apache Kafka&lt;/strong&gt;&lt;/a&gt; comes with ready-made helping classes to subscribe to any topic of the Apache Kafka cluster to retrieve the data stored from an application based on &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt;. Any application can use this feature to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;read latest data stored in the topics from the application based on &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;attach to the topics involved from the application based on &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt; and receive change events upon something was produced&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The ready-made helping classes upon a record is received, deserialize it and returns back the filled Entity.&lt;/p&gt;

&lt;h4&gt;
  
  
  Use cases
&lt;/h4&gt;

&lt;p&gt;The schema used to write the information in the topics are available, or can be defined from the user, so an external application can use the data in many mode:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using the feature to extract the entities stored in the topics outside the application based on &lt;a href="https://learn.microsoft.com/it-it/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Use some features of Apache Kafka like Apache Kafka Streams or Apache Kafka Connect.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An application, not based on Entity Framework Core, can subscribe to the topics to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;store all change events to another medium&lt;/li&gt;
&lt;li&gt;analyze the data or the changes&lt;/li&gt;
&lt;li&gt;Use &lt;a href="https://kafka.apache.org/documentation/streams/" rel="noopener noreferrer"&gt;Apache Kafka Streams&lt;/a&gt;: Apache Kafka comes with the powerful Streams feature. An application based on Streams can analyze streams of data to extract some information or converts the data into something else. It is possible to build an application, based on Apache Kafka Streams, which hear on change events and produce something else or just sores them in another topic containing all events not only the latest (e.g. just like the transaction log of SQL Server does it).&lt;/li&gt;
&lt;li&gt;Use &lt;a href="https://kafka.apache.org/documentation/#connect" rel="noopener noreferrer"&gt;Apache Kafka Connect&lt;/a&gt;: Apache Kafka comes with another powerful feature called Connect: it comes with some ready-made connector which connect Apache Kafka with other systems (database, storage, etc).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt; : While Apache Kafka Streams is an application running alone, Apache Kafka Connect can allocate the connectors using its distributed behavior which load-balance and automatically restarts operation if something is going wrong.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at&lt;/em&gt; &lt;a href="https://kefcore.masesgroup.com/articles/howitworks.html" rel="noopener noreferrer"&gt;&lt;em&gt;https://masesgroup.github.io&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Other articles on this topic are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/mario_mastrodicasa_791193/kefcore-apache-kafka-provider-for-entity-framework-core-1mbi"&gt;Entity Framework Core provider for Apache Kafka — Introduction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/mario_mastrodicasa_791193/entity-framework-core-provider-for-apache-kafka-performance-3m36"&gt;Entity Framework Core provider for Apache Kafka — Performance&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>database</category>
      <category>apachekafka</category>
      <category>entityframeworkcore</category>
      <category>distributedcache</category>
    </item>
    <item>
      <title>Entity Framework Core provider for Apache Kafka - Performance</title>
      <dc:creator>Mario Mastrodicasa</dc:creator>
      <pubDate>Thu, 26 Nov 2026 00:22:56 +0000</pubDate>
      <link>https://dev.to/mario_mastrodicasa/entity-framework-core-provider-for-apache-kafka-performance-3m36</link>
      <guid>https://dev.to/mario_mastrodicasa/entity-framework-core-provider-for-apache-kafka-performance-3m36</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2vq6g0e6g8po808ngos5.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2vq6g0e6g8po808ngos5.jpeg" alt="Photo by Nicolas Hoizey on Unsplash" width="800" height="1200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a continuation of a &lt;a href="https://dev.to/mario_mastrodicasa_791193/kefcore-apache-kafka-provider-for-entity-framework-core-1mbi"&gt;previous article&lt;/a&gt; wrote on &lt;a href="https://github.com/masesgroup/KEFCore" rel="noopener noreferrer"&gt;KEFCore&lt;/a&gt;. This article speaks about new improvements of &lt;a href="https://github.com/masesgroup/KEFCore" rel="noopener noreferrer"&gt;KEFCore&lt;/a&gt; and try to analyze the performances compared to other providers.&lt;/p&gt;

&lt;h2&gt;
  
  
  New features and improvements
&lt;/h2&gt;

&lt;p&gt;Before describe the performances I introduce the new improvements. The latest version of &lt;a href="https://github.com/masesgroup/KEFCore" rel="noopener noreferrer"&gt;KEFCore&lt;/a&gt; comes with some improvements in these areas:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  A new data model to store data into the topics&lt;/li&gt;
&lt;li&gt;  A new serialization approach&lt;/li&gt;
&lt;li&gt;  KNetCompactedReplicator engine, beside Apache Kafka Streams, to store and retrieve data from the Apache Kafka cluster&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s start to describe them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data model
&lt;/h3&gt;

&lt;p&gt;In the &lt;a href="https://dev.to/mario_mastrodicasa_791193/kefcore-apache-kafka-provider-for-entity-framework-core-1mbi"&gt;previous article&lt;/a&gt; the data stored in the topics were more or less raw info and the types depends from the .NET type written in the data model. Without the source code it was not possible to understand the corresponding type for each data in the array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"typeName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"MASES.EntityFrameworkCore.KNet.Test.Blog"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;    &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"http://blogs.msdn.com/adonet0"&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The new data model contains more information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  both the index and the name of the property, so it is possible to reassign back, based on position or name, the value to the Entity of the defined model&lt;/li&gt;
&lt;li&gt;  the type associated to the corresponding value, so it is possible to read the content of the data and report it back to the model; or analyze it with other tools without the knowledge of the original .NET type&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An example is like the following one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"EntityName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"MASES.EntityFrameworkCore.KNet.Test.Blog"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"ClrType"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"MASES.EntityFrameworkCore.KNet.Test.Blog"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"Data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"0"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"PropertyName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"BlogId"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"ClrType"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"System.Int32"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"Value"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"PropertyName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Rating"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"ClrType"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"System.Int32"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"Value"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"2"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"PropertyName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Url"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"ClrType"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"System.String"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"Value"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"http://blogs.msdn.com/adonet7"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Serialization approach
&lt;/h3&gt;

&lt;p&gt;Contrary to the previous version, where data on topic was always a string (simple primary key type like &lt;strong&gt;integer&lt;/strong&gt; were converted into string), the new approach consider the type and use, when available, the standard serializers of Apache Kafka:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  e.g. &lt;strong&gt;integer&lt;/strong&gt; are reported in their raw format and operations done from other tools can use directly that value if needed&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;structured values&lt;/strong&gt; (both complex primary keys or the entity value itself) are managed using the JSON serialization available in .NET 6.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  KNetCompactedReplicator engine
&lt;/h3&gt;

&lt;p&gt;As concluded in &lt;a href="https://dev.to/mario_mastrodicasa_791193/kefcore-apache-kafka-provider-for-entity-framework-core-1mbi"&gt;previous article&lt;/a&gt;, KNet comes with some features over the standard one of Apache Kafka clients. KEFCore now supports KNetCompactedReplicator to manage data store and retrieve. Currently Apache Kafka Streams is used in its most simple way: more or less it reports the data available within the topic. This is the same that KNetCompactedReplicator does.&lt;/p&gt;

&lt;h2&gt;
  
  
  Performance
&lt;/h2&gt;

&lt;p&gt;I briefly introduced the most important improvements made on KEFCore, however without a performance analysis they remains only words.&lt;/p&gt;

&lt;p&gt;The performances of any Entity Framework Core provider are impacted from two different elements:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Each provider connects to a back-end: better is the communication with the back-end better are the performances on retrieve or store data;&lt;/li&gt;
&lt;li&gt; When data are received from the back-end: better is the conversion to the EFCore Entity, or data enumeration, better are the performances to execute the EFCore program.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To measure the performances I need a reference since this kind of tests can be done only in comparison mode.&lt;/p&gt;

&lt;p&gt;About point 1: it is complex to make a right comparison test because the back-end can introduce a great impact and any back-end has its own characteristics.&lt;/p&gt;

&lt;p&gt;About point 2: if I consider that on KEFCore both Apache Kafka Streams and KNetCompactedReplicator approaches stores an in-memory local copy of the data, the comparison can be done against the EFCore &lt;a href="https://learn.microsoft.com/en-us/ef/core/providers/in-memory/" rel="noopener noreferrer"&gt;&lt;strong&gt;InMemory&lt;/strong&gt;&lt;/a&gt; provider: this provider is used to test and debug the model, it does not need any database engine and it works perfectly locally.&lt;/p&gt;

&lt;h3&gt;
  
  
  Approach
&lt;/h3&gt;

&lt;p&gt;First of all I cloned the &lt;a href="https://github.com/masesgroup/KEFCore" rel="noopener noreferrer"&gt;KEFCore repository&lt;/a&gt; at its head version.&lt;/p&gt;

&lt;p&gt;The approach used to make the test is the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Create a &lt;code&gt;KafkaDbContext&lt;/code&gt; will manage the provider under test: overriding &lt;code&gt;OnConfiguring&lt;/code&gt; of &lt;code&gt;KafkaDbContext&lt;/code&gt;it is possible to choose another provider to use like the &lt;a href="https://learn.microsoft.com/en-us/ef/core/providers/in-memory/" rel="noopener noreferrer"&gt;&lt;strong&gt;InMemory&lt;/strong&gt;&lt;/a&gt; provider&lt;/li&gt;
&lt;li&gt; Cleanup and recreate the back-end using &lt;code&gt;EnsureDeleted/EnsureCreated&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Create a set of data and store them in the back-end using Entity Framework Core syntax and dispose the &lt;code&gt;KafkaDbContext&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Create the same &lt;code&gt;KafkaDbContext&lt;/code&gt; of step 1&lt;/li&gt;
&lt;li&gt; Invoke a query which will retrieve the data from the back-end: the elapsed time is the sum of time needed to retrieve the data from back-end (using Apache Kafka the provider communicates with the Apache Kafka cluster) and the execution time of the query itself&lt;/li&gt;
&lt;li&gt; Invoke a second time the same query: the elapsed time is only the execution time of the query itself since the data are available locally&lt;/li&gt;
&lt;li&gt; Execute step 3 and 4 using different queries&lt;/li&gt;
&lt;li&gt; Dispose the &lt;code&gt;KafkaDbContext&lt;/code&gt; to cleanup everything and return to step &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Model and queries
&lt;/h3&gt;

&lt;p&gt;The model used in the test is the same of the &lt;a href="https://dev.to/mario_mastrodicasa_791193/kefcore-apache-kafka-provider-for-entity-framework-core-1mbi"&gt;previous article&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BloggingContext&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;KafkaDbContext&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;DbSet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Blog&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Blogs&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;DbSet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Posts&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Blog&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;Url&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="nc"&gt;Rating&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Posts&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;PostId&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;Title&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;Content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Blog&lt;/span&gt; &lt;span class="nc"&gt;Blog&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code snippet with the queries is the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="nc"&gt;Stopwatch&lt;/span&gt; &lt;span class="n"&gt;watch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Stopwatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Restart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Single&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Stop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;ReportString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"First execution of context.Posts.Single(b =&amp;gt; b.BlogId == 2) takes {watch.Elapsed}. Result is {post}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Restart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Single&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Stop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;ReportString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"Second execution of context.Posts.Single(b =&amp;gt; b.BlogId == 2) takes {watch.Elapsed}. Result is {post}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Restart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Single&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NumberOfElements&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Stop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;ReportString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"Execution of context.Posts.Single(b =&amp;gt; b.BlogId == {config.NumberOfElements - 1}) takes {watch.Elapsed}. Result is {post}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Restart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;all&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;All&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Stop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;ReportString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"Execution of context.Posts.All((o) =&amp;gt; true) takes {watch.Elapsed}. Result is {all}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Blog&lt;/span&gt; &lt;span class="n"&gt;blog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Restart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;blog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Blogs&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Single&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Stop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;ReportString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"First execution of context.Blogs!.Single(b =&amp;gt; b.BlogId == 1) takes {watch.Elapsed}. Result is {blog}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Restart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;blog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Blogs&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Single&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Stop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;ReportString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"Second execution of context.Blogs!.Single(b =&amp;gt; b.BlogId == 1) takes {watch.Elapsed}. Result is {blog}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Restart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;from&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Blogs&lt;/span&gt;
              &lt;span class="n"&gt;join&lt;/span&gt; &lt;span class="n"&gt;pg&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Posts&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="n"&gt;equals&lt;/span&gt; &lt;span class="n"&gt;pg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt;
              &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;pg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt;
              &lt;span class="n"&gt;select&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;pg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Stop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;ReportString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"Execution of first complex query takes {watch.Elapsed}. Result is {result.Count} element{(result.Count == 1 ? string.Empty : "&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="s2"&gt;")}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Restart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;from&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Blogs&lt;/span&gt;
               &lt;span class="n"&gt;join&lt;/span&gt; &lt;span class="n"&gt;pg&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Posts&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="n"&gt;equals&lt;/span&gt; &lt;span class="n"&gt;pg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt;
               &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rating&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
               &lt;span class="n"&gt;select&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;pg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;op&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Stop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;ReportString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"Execution of second complex query takes {watch.Elapsed}. Result is {result2.Count} element{(result2.Count == 1 ? string.Empty : "&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="s2"&gt;")}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Results
&lt;/h3&gt;

&lt;p&gt;I do not list here a set of number or graphs and I don’t want to wrote an hypercube matrix of tested cases, since the tests can be impacted from many conditions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; machine (KEFCore and InMemory): CPU and available memory have impact&lt;/li&gt;
&lt;li&gt; Apache Kafka cluster speed and network congestion (only KEFCore): the cluster shall run on a Unix (Linux) machine and the test was executed on Windows&lt;/li&gt;
&lt;li&gt; configuration used for Producer/Consumer/Streams (only KEFCore): changing the parameters will change the test results&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I want to summarize what I measured, everyone else can do the test using the project in &lt;a href="https://github.com/masesgroup/KEFCore" rel="noopener noreferrer"&gt;KEFCore repository&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://learn.microsoft.com/en-us/ef/core/providers/in-memory/" rel="noopener noreferrer"&gt;&lt;strong&gt;InMemory&lt;/strong&gt;&lt;/a&gt; provider surpasses everything, however it was expected.&lt;/p&gt;

&lt;p&gt;Using KNetCompactedReplicator (enabling it with UseCompactedReplicator property):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  the first query takes more time to be executed than the second one and this was expected: the extra time depends from the network and configuration parameters (conditions 2 and 3) and time used to deserialize the data (condition 1)&lt;/li&gt;
&lt;li&gt;  the second query, compared to InMemory, needs more time: this condition is related on how &lt;a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.storage.valuebuffer" rel="noopener noreferrer"&gt;ValueBuffers&lt;/a&gt; are built; InMemory provider has ready-made data, KEFCore shall build them from the structured object stored in KNetCompactedReplicator, so the execution time depends from CPU speed (condition 1)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using Apache Kafka Streams:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  the first query takes more time to be executed than the second one and this was expected: in this case the extra time (more than the KNetCompactedReplicator case) depends mainly from startup phases of allocated Streams and maybe from configuration parameters (condition 3)&lt;/li&gt;
&lt;li&gt;  the second query, compared to KNetCompactedReplicator, needs more time: this condition is related on how &lt;a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.storage.valuebuffer" rel="noopener noreferrer"&gt;ValueBuffers&lt;/a&gt; are built; KNetCompactedReplicator has executed the deserialization process while the data was received and needs to build only &lt;a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.storage.valuebuffer" rel="noopener noreferrer"&gt;ValueBuffers&lt;/a&gt;, while with Apache Kafka Streams the data are stored as raw bytes in the JVM: KEFCore shall request the raw bytes, deserialize them and finally build the &lt;a href="https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.storage.valuebuffer" rel="noopener noreferrer"&gt;ValueBuffers&lt;/a&gt;. The execution time depends from CPU speed (condition 1).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Between KNetCompactedReplicator and Apache Kafka Streams surely I choose the first. The current implementation of KEFCore based Apache Kafka Streams is very poor and, as concluded in the &lt;a href="https://dev.to/mario_mastrodicasa_791193/kefcore-apache-kafka-provider-for-entity-framework-core-1mbi"&gt;previous article&lt;/a&gt;, an improvement on its use can come from the direct conversion of EFCore queries into flows of Apache Kafka Streams.&lt;/p&gt;

&lt;p&gt;Some work was done on KEFCore to have a well working provider, other shall be done. If you like it you can test it, provide feedback, open issues.&lt;/p&gt;

&lt;p&gt;Other articles on this topic are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://dev.to/mario_mastrodicasa_791193/kefcore-apache-kafka-provider-for-entity-framework-core-1mbi"&gt;Entity Framework Core provider for Apache Kafka — Introduction&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://dev.to/mario_mastrodicasa_791193/entity-framework-core-provider-for-apache-kafka-how-it-works-and-use-cases-1j66"&gt;Entity Framework Core provider for Apache Kafka — How it works and use cases&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>kafka</category>
      <category>efcore</category>
    </item>
    <item>
      <title>KEFCore: Apache Kafka provider for Entity Framework Core</title>
      <dc:creator>Mario Mastrodicasa</dc:creator>
      <pubDate>Thu, 26 Nov 2026 00:18:34 +0000</pubDate>
      <link>https://dev.to/mario_mastrodicasa/kefcore-apache-kafka-provider-for-entity-framework-core-1mbi</link>
      <guid>https://dev.to/mario_mastrodicasa/kefcore-apache-kafka-provider-for-entity-framework-core-1mbi</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvpbau88cpspycir0cx2j.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvpbau88cpspycir0cx2j.jpeg" alt="Photo by Ferenc Almasi on Unsplash" width="800" height="491"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article I don’t speak about usage of &lt;a href="https://learn.microsoft.com/en-us/ef/core/" rel="noopener noreferrer"&gt;Entity Framework Core&lt;/a&gt;, there are tons of documentation about its usage, but I speak about back-ends. EFCore (Entity Framework Core) relies on providers to communicate with back-ends, the full list is available &lt;a href="https://learn.microsoft.com/en-us/ef/core/providers" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The question is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Can EFCore use Apache Kafka as back-end?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The short answer is &lt;strong&gt;yes&lt;/strong&gt; and long answer is &lt;strong&gt;&lt;a href="https://github.com/masesgroup/KEFCore" rel="noopener noreferrer"&gt;KEFCore: Entity Framework Core provider for Apache Kafka&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;KEFCore&lt;/strong&gt; is a provider able to use Apache Kafka as back-end for Entity Framework Core.&lt;/p&gt;

&lt;h3&gt;
  
  
  Model definition
&lt;/h3&gt;

&lt;p&gt;The model used in the example is the same available &lt;a href="https://learn.microsoft.com/en-us/ef/core/" rel="noopener noreferrer"&gt;here&lt;/a&gt;, the difference is in the provider requested: in the example of the repository it is used an Apache Kafka cluster inheriting from &lt;a href="https://github.com/masesgroup/KEFCore/blob/master/src/net/KEFCore/Infrastructure/KafkaDbContext.cs" rel="noopener noreferrer"&gt;KafkaDbContext&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;BloggingContext&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;KafkaDbContext&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;DbSet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Blog&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Blogs&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;DbSet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Posts&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Blog&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;Url&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;long&lt;/span&gt; &lt;span class="nc"&gt;Rating&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Posts&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;PostId&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;Title&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;Content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Blog&lt;/span&gt; &lt;span class="nc"&gt;Blog&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/masesgroup/KEFCore/blob/master/src/net/KEFCore/Infrastructure/KafkaDbContext.cs" rel="noopener noreferrer"&gt;KafkaDbContext&lt;/a&gt; is an helper class which hides the standard way to declare the provider to be used, it overrides the &lt;code&gt;OnConfiguring&lt;/code&gt; method of &lt;code&gt;DbContext&lt;/code&gt;, checks the mandatory information and sets the required information.&lt;/p&gt;

&lt;h3&gt;
  
  
  Back-end storage fill and query
&lt;/h3&gt;

&lt;p&gt;With the following code the back-end is filled in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BloggingContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;BootstrapServers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;serverToUse&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;ApplicationId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"TestApplication"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;DbName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"TestDB"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;StreamsConfigBuilder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;streamConfig&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;EnsureDeleted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Database&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;EnsureCreated&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Blog&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;Url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"http://blogs.msdn.com/adonet"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nc"&gt;Posts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="nc"&gt;Title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"title"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="nc"&gt;Content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nc"&gt;Rating&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SaveChanges&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And with the following code the data stored in the back-end can be queried:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BloggingContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;BootstrapServers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;serverToUse&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;ApplicationId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"TestApplication"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;DbName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"TestDB"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;StreamsConfigBuilder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;streamConfig&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Single&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Single&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;all&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;All&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;blog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Blogs&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Single&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Blogs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AsQueryable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToQueryString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Context initialization
&lt;/h3&gt;

&lt;p&gt;The information used in the example to initialize the context are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;BootstrapServers&lt;/strong&gt;: a &lt;strong&gt;mandatory&lt;/strong&gt; string containing a comma separated list of brokers, in the form &lt;em&gt;host:port&lt;/em&gt;, to identify the Kafka cluster to be used&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;ApplicationId&lt;/strong&gt;: an &lt;strong&gt;optional&lt;/strong&gt; identifier used from Apache Kafka Streams to distinguish multiple applications, if not set it is automatically generated&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;DbName&lt;/strong&gt;: a &lt;strong&gt;mandatory&lt;/strong&gt; identifier used to distinguish, within Apache Kafka cluster, topics for a specific scope&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;StreamsConfigBuilder&lt;/strong&gt;: an &lt;strong&gt;optional&lt;/strong&gt; instance of &lt;em&gt;StreamsConfigBuilder&lt;/em&gt; used to give specific settings to Apache Kafka Streams, it is used from the test&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Other options available are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;ProducerConfigBuilder&lt;/strong&gt;: an &lt;strong&gt;optional&lt;/strong&gt; instance of &lt;em&gt;ProducerConfigBuilder&lt;/em&gt; used to give specific settings to Apache Kafka Producer&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;TopicConfigBuilder&lt;/strong&gt;: an &lt;strong&gt;optional&lt;/strong&gt; instance of &lt;em&gt;TopicConfigBuilder&lt;/em&gt; used to give specific settings to KEFCore when topics are created if not already available&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;UsePersistentStorage&lt;/strong&gt;: set to true if Apache Kafka Streams shall use a persistent storage across application run, otherwise data are stored in memory&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What’s in the back-end
&lt;/h3&gt;

&lt;p&gt;In the previous application the provider will create two topics (see &lt;a href="https://kafka.apache.org" rel="noopener noreferrer"&gt;Apache Kafka site&lt;/a&gt; for explanation), one for &lt;em&gt;Blogs&lt;/em&gt; and one for &lt;em&gt;Posts&lt;/em&gt;. Using an application to read information from an Apache Kafka cluster it is possible to read what was written in and then read from the topics.&lt;/p&gt;

&lt;p&gt;The topics are named in the following format: &lt;em&gt;DbName&lt;/em&gt;.&lt;em&gt;FullQualifiedDataClassName&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Considering that the namespace in the example is &lt;strong&gt;MASES.EntityFrameworkCore.KNet.Test&lt;/strong&gt;, the previous application creates two topics named:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;TestDB.MASES.EntityFrameworkCore.KNet.Test.Blog&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;TestDB.MASES.EntityFrameworkCore.KNet.Test.Post&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The provider stores the key information (&lt;em&gt;BlogId&lt;/em&gt; and &lt;em&gt;PostId&lt;/em&gt;) as single element, while the data, including the key itself, are stored as a JSON string which contains the .NET type identifier to be used during deserialization. A screenshot of the Apache Kafka client I used is the following:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjfx4fzehno3eg4afyxle.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjfx4fzehno3eg4afyxle.png" alt="Topics in Apache Kafka cluster" width="800" height="419"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A value of &lt;em&gt;Blog&lt;/em&gt; entry is the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"typeName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"MASES.EntityFrameworkCore.KNet.Test.Blog"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;    &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"http://blogs.msdn.com/adonet0"&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A value of &lt;em&gt;Post&lt;/em&gt; entry is the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"typeName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"MASES.EntityFrameworkCore.KNet.Test.Post"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;    &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;"title"&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looking at the previous JSONs, and knowing how the types are defined, it is possible to associate the data array in the JSON to the corresponding types and meaning. Using other kind of application based on Apache Kafka, consuming from the topics it is possible to use the data of the topics for other reasons.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the provider works
&lt;/h2&gt;

&lt;p&gt;In an &lt;a href="https://dev.to/mario_mastrodicasa_791193/knet-a-new-way-to-use-apache-kafka-from-net-b33"&gt;previous article&lt;/a&gt; I spoke about KNet, a new way to access the features of Apache Kafka from .NET, and I introduced the ability of KNet to use Apache Kafka Streams. KEFCore relies on KNet and specifically on Apache Kafka Streams. Now I’m going to speak more about KEFCore, firstly introducing Apache Kafka Streams.&lt;/p&gt;

&lt;h3&gt;
  
  
  Apache Kafka Streams
&lt;/h3&gt;

&lt;p&gt;This article don’t want to speak about Apache Kafka Streams in deep, for a complete introduction the reader can surf the following link:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://kafka.apache.org/documentation/streams/" rel="noopener noreferrer"&gt;https://kafka.apache.org/documentation/streams/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://docs.confluent.io/platform/current/streams/overview.html" rel="noopener noreferrer"&gt;https://docs.confluent.io/platform/current/streams/overview.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://docs.conduktor.io/desktop/features/kafka-streams/" rel="noopener noreferrer"&gt;https://docs.conduktor.io/desktop/features/kafka-streams/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I want to concentrate on two concepts behind Apache Kafka Streams:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://kafka.apache.org/26/javadoc/org/apache/kafka/streams/kstream/KStream.html" rel="noopener noreferrer"&gt;KStream&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://kafka.apache.org/23/javadoc/org/apache/kafka/streams/kstream/KTable.html" rel="noopener noreferrer"&gt;KTable&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Apache Kafka stores information within topics using records of key-value pair ordered by their produce sequence: in the article I consider there is a stream of key-value pair records stored in a container named topic. Surf &lt;a href="https://kafka.apache.org/" rel="noopener noreferrer"&gt;Apache Kafka site&lt;/a&gt; to understand more on this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://kafka.apache.org/26/javadoc/org/apache/kafka/streams/kstream/KStream.html" rel="noopener noreferrer"&gt;KStream&lt;/a&gt; represent exactly the stream of key-value pair records within the topic. While &lt;a href="https://kafka.apache.org/23/javadoc/org/apache/kafka/streams/kstream/KTable.html" rel="noopener noreferrer"&gt;KTable&lt;/a&gt; represents the same data in a table forms of records built by two columns: key and value. There is a duality between &lt;a href="https://kafka.apache.org/26/javadoc/org/apache/kafka/streams/kstream/KStream.html" rel="noopener noreferrer"&gt;KStream&lt;/a&gt; and &lt;a href="https://kafka.apache.org/23/javadoc/org/apache/kafka/streams/kstream/KTable.html" rel="noopener noreferrer"&gt;KTable&lt;/a&gt;, KEFCore uses KTable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Database equivalency
&lt;/h3&gt;

&lt;p&gt;A database (SQL and/or NoSQL) is a set of data record, each record can be viewed as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Primary Key&lt;/strong&gt;: a single identifier, or a tuple of identifiers, that distinguish the single record; the single identifier can be equivalent to the key of a Kafka record, if the primary key has multiple elements the corresponding Kafka key can be a structure containing the identifiers&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Values&lt;/strong&gt;: a set of items containing the data of the record; if the set has a single item it is equivalent to the value of a Kafka record, if the set has multiple items the corresponding Kafka value can be a structure containing the set of items&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What I described is a possible equivalence between a database back-end and Apache Kafka back-end. In RDBMS the primary key can be unique and in this case Apache Kafka comes with a special feature named &lt;a href="https://developer.confluent.io/courses/architecture/compaction/" rel="noopener noreferrer"&gt;compacted topic&lt;/a&gt;: without entering in details, from the point of view of the final result, if we update the topic using the same key the oldest values with the same key are discarded and only the latest value will be available.&lt;/p&gt;

&lt;p&gt;KEFCore uses compacted topics to reduce the size of the data stored in the Apache Kafka cluster.&lt;/p&gt;

&lt;h3&gt;
  
  
  Both together
&lt;/h3&gt;

&lt;p&gt;With the previous considerations an entire database could be converted in many Kafka topics: each SQL database table can be stored in a topic, or many NoSQL documents can be stored in Kafka topics. With this consideration, I can recall a previous chapter where I shown the content of the Apache Kafka topics of the example, the data managed from EFCore application are stored in the Apache Kafka cluster; with a migration application, not available in KEFCore, any database storing EFCore data can be converted into Apache Kafka topics.&lt;/p&gt;

&lt;h3&gt;
  
  
  Apache Kafka as distributed cache
&lt;/h3&gt;

&lt;p&gt;Without thinking to an equivalence to databases, from the point of view of the data, it is possible to state that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  data are stored uniquely, within the associated topics, with their key-value pair&lt;/li&gt;
&lt;li&gt;  data are persisted and are available to any client requesting them from the topics&lt;/li&gt;
&lt;li&gt;  in a distributed environment any modification stored within the associated topics is sent to any client subscribed to the topics&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The above sentences make me thinking to a distributed cache able to sent real-time updates to the subscribed clients, simplifying it is possible to think to something similar to &lt;a href="https://redis.io/" rel="noopener noreferrer"&gt;Redis&lt;/a&gt;. Using KEFCore, an application based on EFCore, can take advantages of Apache Kafka and use it instead of Redis.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Update — 2026&lt;/strong&gt;: Three years have passed since this article was published. KEFCore has evolved and most of the following are available. If you want to see where the project stands today, read the follow-up: &lt;a href="https://dev.to/mario_mastrodicasa_791193/kefcore-re-engineered-apache-kafka-as-an-entity-framework-core-provider-three-years-later-4i0h"&gt;KEFCore re-engineered: Apache Kafka™ as an Entity Framework Core provider, three years later&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This article just introduced &lt;a href="https://github.com/masesgroup/KEFCore" rel="noopener noreferrer"&gt;KEFCore&lt;/a&gt; as an alternative provider for Entity Framework Core. As stated at the beginning of the article it is still in development however the test code is working and anyone can test it. What is possible to highlight using the example is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The data are stored in the topics as string, simple types are converted in string too; the back conversion is connected to the data type retrieved from the application assembly: if the type change the data stored cannot be converted back&lt;/li&gt;
&lt;li&gt;  The structure used to store the data is more or less fixed; the schema of the JSON is fixed and the type, within the JSON, is retrieved from the application assembly&lt;/li&gt;
&lt;li&gt;  At startup, the initialization takes a lot of time and the first query is done slowly; trying to avoid &lt;code&gt;context.Database.EnsureDeleted();&lt;/code&gt; and using &lt;code&gt;UsePersintentStorage=true&lt;/code&gt; , the application seems to work better&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some possible improvements can be:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Create and publish the JSON schema of involved data types, this can help external applications, consuming from or producing to the topics, to manage the data without retrieve the .NET data type stored in the assembly&lt;/li&gt;
&lt;li&gt; KNet comes with the &lt;code&gt;[KNetCompactedReplicator](https://github.com/masesgroup/KNet/blob/master/src/net/KNet/Specific/KNetCompactedReplicator.cs)&lt;/code&gt; class which can be used to retrieve a compacted topic and manage the data as a .NET dictionary avoiding Apache Kafka Streams; this can help the condition where Apache Kafka is used as a distributed cache&lt;/li&gt;
&lt;li&gt; Use Apache Kafka Streams when there are some relationship between tables in queries which can be resolved using features of Apache Kafka Streams: convert queries of EFCore into flows of Apache Kafka Streams, this can speed-up the responsiveness of the applications&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Some work shall be done on KEFCore to have a well working provider, however it is working and anyone can test it. If you like it you can test it, provide feedback, open issues.&lt;/p&gt;

&lt;p&gt;Other articles on this topic are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://dev.to/mario_mastrodicasa_791193/kefcore-re-engineered-apache-kafka-as-an-entity-framework-core-provider-three-years-later-4i0h"&gt;KEFCore re-engineered: Apache Kafka™ as an Entity Framework Core provider, three years later&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://dev.to/mario_mastrodicasa_791193/entity-framework-core-provider-for-apache-kafka-performance-3m36"&gt;Entity Framework Core provider for Apache Kafka — Performance&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://dev.to/mario_mastrodicasa_791193/entity-framework-core-provider-for-apache-kafka-how-it-works-and-use-cases-1j66"&gt;Entity Framework Core provider for Apache Kafka — How it works and use cases&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>kafka</category>
      <category>efcore</category>
    </item>
    <item>
      <title>KNet: a new way to use Apache Kafka from .NET</title>
      <dc:creator>Mario Mastrodicasa</dc:creator>
      <pubDate>Thu, 26 Nov 2026 00:14:37 +0000</pubDate>
      <link>https://dev.to/mario_mastrodicasa/knet-a-new-way-to-use-apache-kafka-from-net-b33</link>
      <guid>https://dev.to/mario_mastrodicasa/knet-a-new-way-to-use-apache-kafka-from-net-b33</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2hni80sc4sdme9bh0ij7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2hni80sc4sdme9bh0ij7.png" alt="Apache Kafka (image from Confluent site)" width="473" height="333"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://kafka.apache.org/" rel="noopener noreferrer"&gt;Apache Kafka&lt;/a&gt; is well known and widely used: this &lt;a href="https://kafka.apache.org/uses" rel="noopener noreferrer"&gt;site&lt;/a&gt; reports many real world use cases. There are many client applications and libraries: &lt;a href="https://cwiki.apache.org/confluence/display/KAFKA/Clients" rel="noopener noreferrer"&gt;here&lt;/a&gt; the full list. In this article I want to speak about KNet, because it uses a different approach to interact with Apache Kafka from .NET, it was firstly introduced in another &lt;a href="https://dev.to/mario_mastrodicasa_791193/java-apis-written-in-c-jvm-and-net-side-by-side-31bk"&gt;article&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The approach
&lt;/h2&gt;

&lt;p&gt;The most known client libraries are the one managed from Confluent: the libraries are wrappers around a common library written for C/C++ (&lt;a href="https://github.com/confluentinc/librdkafka" rel="noopener noreferrer"&gt;librdkafka&lt;/a&gt;). The library is almost complete for most common purposes and I used it in many applications, however it rewrites the classes (e.g. producer, consumer, etc) and the communication protocol to connect to an Apache Kafka cluster; this implies that any change, improvement, bug fix on Apache Kafka implementation shall be applied to the client library, with extra coding cycles and tests to be done to validate it. This doubles, at least, the effort to have a stable solution.&lt;/p&gt;

&lt;p&gt;Now I start to introduce to the reader &lt;a href="https://github.com/masesgroup/KNet" rel="noopener noreferrer"&gt;KNet&lt;/a&gt;: contrary to libraries mentioned before, KNet does not rewrites again anything of Apache Kafka, instead it executes directly the Java code of the validated Apache Kafka distribution from .NET, rewriting the APIs only. So KNet has &lt;strong&gt;the same&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://cwiki.apache.org/confluence/display/KAFKA/Kafka+Improvement+Proposals" rel="noopener noreferrer"&gt;Kafka Improvement Proposals&lt;/a&gt; available in the underlying Apache Kafka distribution&lt;/li&gt;
&lt;li&gt;  API surface of the underlying Apache Kafka distribution&lt;/li&gt;
&lt;li&gt;  Cybersecurity&lt;/li&gt;
&lt;li&gt;  Documentation&lt;/li&gt;
&lt;li&gt;  Known bugs and limitations&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What’s available?
&lt;/h2&gt;

&lt;p&gt;With KNet everything is available in the official, JVM based, Apache Kafka distribution is available to .NET user too. An incomplete list is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Producer and Consumer&lt;/strong&gt;: classic APIs, plus KNet specific Producer and Consumer;&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://kafka.apache.org/documentation/streams/" rel="noopener noreferrer"&gt;&lt;strong&gt;Apache Kafka Streams&lt;/strong&gt;&lt;/a&gt;: the same APIs available in Java version; this functionality is not available with other products;&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;KNet Connect SDK&lt;/strong&gt;: a framework, available only with KNet, to build connectors using .NET; without KNet, connectors shall be written using Java;&lt;/li&gt;
&lt;li&gt;  Full set of administrative APIs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Beside the above APIs there are some tools and ready made containers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;KNetPS&lt;/strong&gt;: a PowerShell module to interact with Apache Kafka using PowerShell;&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;KNetCLI&lt;/strong&gt;: a command line interface to execute commands like you can do with the binary distribution; also available a ready made container;&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;KNetConnect&lt;/strong&gt;: a command line interface to manage &lt;a href="https://docs.confluent.io/platform/current/connect/index.html" rel="noopener noreferrer"&gt;Apache Kafka Connect&lt;/a&gt; framework; also available a ready made container.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to use KNet?
&lt;/h2&gt;

&lt;p&gt;KNet offers multiple way to use Apache Kafka from .NET:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Classic&lt;/strong&gt;: the approach follows exactly the same APIs used in Java&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Specific&lt;/strong&gt;: the approach adds new APIs more .NET aware&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Classic
&lt;/h3&gt;

&lt;p&gt;As stated in &lt;strong&gt;The approach&lt;/strong&gt; chapter, KNet reproduces what’s available in the Apache Kafka distribution and you don’t need to learn other APIs. The same examples and code available on the net can be used from any .NET based application. Ad example this is the code that can be used to prepare producer configuration properties:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Properties&lt;/span&gt; &lt;span class="n"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Properties&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ProducerConfig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;BOOTSTRAP_SERVERS_CONFIG&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;serverToUse&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ProducerConfig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;ACKS_CONFIG&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"all"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ProducerConfig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;RETRIES_CONFIG&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ProducerConfig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;LINGER_MS_CONFIG&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ProducerConfig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;KEY_SERIALIZER_CLASS_CONFIG&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"org.apache.kafka.common.serialization.StringSerializer"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ProducerConfig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;VALUE_SERIALIZER_CLASS_CONFIG&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"org.apache.kafka.common.serialization.StringSerializer"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then the previous result can be used to create the Producer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;KafkaProducer&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The previous code snippets are exactly the same of the one used in Java!&lt;/p&gt;

&lt;p&gt;The same documentation available in &lt;a href="https://kafka.apache.org/documentation/#api" rel="noopener noreferrer"&gt;Apache Kafka documentation&lt;/a&gt; can be used to identify the configuration properties and their meaning, the best API to use and so on.&lt;/p&gt;

&lt;p&gt;One limitation with classic approach comes with the usable types. A &lt;code&gt;KafkaProducer&amp;lt;TKey, TValue&amp;gt;&lt;/code&gt; can accept only primitive types (&lt;em&gt;bool&lt;/em&gt;, &lt;em&gt;byte&lt;/em&gt;, &lt;em&gt;byte[]&lt;/em&gt;, &lt;em&gt;int&lt;/em&gt;, …) or types reflected from a concrete Java type: an user who wants to define its own structured type shall create it in Java and then reflect it in C#.&lt;/p&gt;

&lt;p&gt;To solve the previous problem, and add many other features, KNet comes with some &lt;strong&gt;specific&lt;/strong&gt; APIs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Specific
&lt;/h3&gt;

&lt;p&gt;Beside the classic approach, KNet comes with other features more comfortable for .NET users. Ad example the configuration properties can be built using the following approach:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="nc"&gt;Properties&lt;/span&gt; &lt;span class="n"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ProducerConfigBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                                        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithBootstrapServers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;serverToUse&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                                        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithAcks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ProducerConfig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Acks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;All&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                                        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithRetries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                                        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithLingerMs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                                        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithKeySerializerClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"org.apache.kafka.common.serialization.StringSerializer"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                                        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithValueSerializerClass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"org.apache.kafka.common.serialization.StringSerializer"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                                        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToProperties&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As stated in &lt;strong&gt;What’s available?&lt;/strong&gt; chapter, KNet offers other APIs and a Producer can be allocated using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;KNetProducer&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To manage structured types defined in C# (without create them in Java) it is possible to define something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;keySerDes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;JsonSerDes&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MyKeyType&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;valueSerDes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;JsonSerDes&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MyValueType&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;KNetProducer&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MyKeyType&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;MyValueType&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;props&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;keySerDes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;valueSerDes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The previous code uses a &lt;code&gt;JsonSerDes&lt;/code&gt; to manage serialization and deserialization of the user defined types &lt;code&gt;MyKeyType&lt;/code&gt; and &lt;code&gt;MyValueType&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Within the KNet suite there are multiple ready made serializer/deserializer which uses different technologies:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://www.nuget.org/packages/MASES.KNet.Serialization.Avro" rel="noopener noreferrer"&gt;MASES.KNet.Serialization.Avro&lt;/a&gt;: based on &lt;a href="https://en.wikipedia.org/wiki/Apache_Avro" rel="noopener noreferrer"&gt;AVRO&lt;/a&gt; format&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.nuget.org/packages/MASES.KNet.Serialization.Json" rel="noopener noreferrer"&gt;MASES.KNet.Serialization.Json&lt;/a&gt;: based on &lt;a href="https://en.wikipedia.org/wiki/JSON" rel="noopener noreferrer"&gt;Json&lt;/a&gt; format&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.nuget.org/packages/MASES.KNet.Serialization.MessagePack" rel="noopener noreferrer"&gt;MASES.KNet.Serialization.MessagePack&lt;/a&gt;: based on &lt;a href="https://en.wikipedia.org/wiki/MessagePack" rel="noopener noreferrer"&gt;MessagePack&lt;/a&gt; format&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.nuget.org/packages/MASES.KNet.Serialization.Protobuf" rel="noopener noreferrer"&gt;MASES.KNet.Serialization.Protobuf&lt;/a&gt;: based on &lt;a href="https://en.wikipedia.org/wiki/Protocol_Buffers" rel="noopener noreferrer"&gt;Google.Protobuf&lt;/a&gt; format&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Other features are &lt;a href="https://kafka.apache.org/documentation/streams/" rel="noopener noreferrer"&gt;&lt;strong&gt;Apache Kafka Streams&lt;/strong&gt;&lt;/a&gt; and &lt;strong&gt;KNet Connect SDK.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Performance
&lt;/h2&gt;

&lt;p&gt;I spoke about the usage, however in real world applications one important element are the performances. Looking at the repository there are some tests which try to measure the performance and there is page reporting the &lt;a href="https://github.com/masesgroup/KNet/blob/043f14e45f3a5dde112397607bb248386675232c/src/net/Documentation/articles/performance.md" rel="noopener noreferrer"&gt;performance results&lt;/a&gt; and the configuration parameters used.&lt;/p&gt;

&lt;h3&gt;
  
  
  Approach
&lt;/h3&gt;

&lt;p&gt;The performances are measured using a compare approach and the reason is clear: too many conditions can impact the measures. The comparison is done against the most used .NET client library (Confluent.Kafka), the one managed from &lt;a href="https://www.confluent.io/" rel="noopener noreferrer"&gt;Confluent Inc&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The approach used try to minimize external side effects and concentrates only on the library comparison. So:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The communication, between client and server, is based on an high speed network&lt;/li&gt;
&lt;li&gt;  The data exchanged are array of bytes to avoid exogenous effects from serialization&lt;/li&gt;
&lt;li&gt;  There is no compression to avoid exogenous effects from different compression libraries&lt;/li&gt;
&lt;li&gt;  There is no ack and in-sync replica is set to 1 so the exogenous storage effects are reduced: records are dispatched to consumer without wait that the records are stored&lt;/li&gt;
&lt;li&gt;  The parameter used to setup producers and consumers of both libraries are the same where this is applicable&lt;/li&gt;
&lt;li&gt;  The effects from different threading models, and data enqueuing patterns, can impact the performances, but this is implicit because we are comparing them 😅&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Benchmarks
&lt;/h3&gt;

&lt;p&gt;The evaluation of the performances are done using two different kind of benchmarks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Send-Receive&lt;/strong&gt;: the benchmark first produces a set of records, then it consumes the same number of records previously produced. The measurements (produce and consume) are done alone on each direction varying the data length and the number of packets, the tests alternate between KNet and Confluent.Kafka; the measurements are repeated multiple times (with the same length and packets) to create a statistic set and reduce exogenous effects. &lt;strong&gt;Considering statistically distributed the impact of network and server, the benchmark measure the performance of the libraries.&lt;/strong&gt; The final measures are reported as the ratio between the capability of KNet over Confluent.Kafka.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;RoundTrip&lt;/strong&gt;: this benchmark works in this way: while it produces records in main thread, it consumes them in an another thread to simulate a consumer in another process. Using a single process it is possible to synchronize, with the Operating System primitives, that the producer starts when the consumer is ready (it has received subscribe notification). The record value contains a byte array like in the previous benchmark, while the key of the record contains the machine ticks: when the record is produced the current ticks are stored as the record key, when the record is received the ticks in the record key are subtracted from current ticks: this is the measure of the time needed, from a ready consumer, to receive record from a producer, i.e. it contains the time (round trip) spent from the library, network and server. &lt;strong&gt;Considering statistically distributed the impact of network and server, the benchmark measure the performance of the libraries.&lt;/strong&gt; The measurements are done varying the data length and the number of packets, the tests alternate between KNet and Confluent.Kafka; the measurements are repeated multiple times (with the same length and packets) to create a statistic set to reduce exogenous effects. The final measures are reported as the ratio between the capability of KNet over Confluent.Kafka.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Results
&lt;/h3&gt;

&lt;p&gt;The results from previous tests, available in &lt;a href="https://github.com/masesgroup/KNet/blob/043f14e45f3a5dde112397607bb248386675232c/src/net/Documentation/articles/performance.md" rel="noopener noreferrer"&gt;performance results&lt;/a&gt; page, are synthesized in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Send-Receive&lt;/strong&gt;: in this benchmark the test conditions impacts the result and it is not very clear which one (KNet or Confluent.Kafka) is the best choice;&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;RoundTrip&lt;/strong&gt;: in this benchmark seems that KNet offers always the best performance, anyway the test results are few and maybe in other conditions Confluent.Kafka works better.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The configuration parameters used may impact on the results, because KNet and Confluent.Kafka uses different threading models and data enqueuing patterns, so it is not possible to take a final conclusion. Ad example, trying the same benchmarks on a cluster hosted in the cloud the performances of both libraries changes.&lt;/p&gt;

&lt;h3&gt;
  
  
  My personal consideration
&lt;/h3&gt;

&lt;p&gt;In &lt;a href="https://github.com/confluentinc/librdkafka" rel="noopener noreferrer"&gt;librdkafka&lt;/a&gt; repository (the library behind Confluent.Kafka) there is this sentence:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It was designed with message delivery reliability and high performance in mind, current figures exceed 1 million msgs/second for the producer and 3 million msgs/second for the consumer.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;However I don’t find any reference on where and how the tests were done, I mean the information reported on &lt;a href="https://github.com/masesgroup/KNet/blob/043f14e45f3a5dde112397607bb248386675232c/src/net/Documentation/articles/performance.md" rel="noopener noreferrer"&gt;performance results&lt;/a&gt; page which describes how the measures are done. When I used the library in some C++ projects the record exchanged varies from few bytes (90) to millions (2–3 Mb), however under heavy stress condition the limit reported above was never reached.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;KNet, using the official Apache Kafka packages, offers the same APIs and, in general, the same performances of official Apache Kafka, plus shares the documentation and adds other features not available on .NET. Confluent.Kafka uses a different approach and it is based on librdkafka (C/C++ library): Confluent.Kafka is the reference library for the .NET developers.&lt;/p&gt;

&lt;p&gt;KNet is aligned to latest KIPs and protocols, while Confluent.Kafka reports these limits (Kafka max is the one of KNet):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://github.com/confluentinc/librdkafka/blob/master/INTRODUCTION.md#supported-kips" rel="noopener noreferrer"&gt;Supported KIPs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://github.com/confluentinc/librdkafka/blob/master/INTRODUCTION.md#supported-protocol-versions" rel="noopener noreferrer"&gt;Supported protocols&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both libraries give benefits and drawbacks, I’m not able to say which is the right choice: the reader knows its own project. What I can say is that the choice depends from many factors, some of them are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Cybersecurity&lt;/li&gt;
&lt;li&gt;  Long and short term compatibility&lt;/li&gt;
&lt;li&gt;  Long term maintainability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now the reader knows KNet too, I leave the choice to him 😜.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>kafka</category>
      <category>java</category>
    </item>
    <item>
      <title>Java and .NET In-Process Bridges in 2026: Architectural Approaches Compared</title>
      <dc:creator>Mario Mastrodicasa</dc:creator>
      <pubDate>Thu, 26 Nov 2026 00:13:04 +0000</pubDate>
      <link>https://dev.to/mario_mastrodicasa/java-and-net-in-process-bridges-in-2026-architectural-approaches-compared-5d6f</link>
      <guid>https://dev.to/mario_mastrodicasa/java-and-net-in-process-bridges-in-2026-architectural-approaches-compared-5d6f</guid>
      <description>&lt;p&gt;When an enterprise system needs Java and .NET to work together, the default reflex is often to put a network boundary between them: spin up a REST service, define a gRPC contract, or drop a message broker in the middle.&lt;/p&gt;

&lt;p&gt;That works fine when loose coupling matters more than latency. It falls apart when you are passing high-frequency events, large binary buffers, or complex object graphs—or when you simply need to reuse a battle-tested Java 8 library inside a modern .NET 10 application without rewriting thousands of lines of code.&lt;/p&gt;

&lt;p&gt;In those scenarios, &lt;strong&gt;in-process bridging&lt;/strong&gt;—running the JVM and the CLR inside the exact same OS process—eliminates network serialization entirely.&lt;/p&gt;

&lt;p&gt;However, "in-process bridge" is an umbrella term covering very different architectures. Let's look at the three main engineering approaches available in 2026 and their real-world trade-offs.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Bytecode-to-IL Transpilation (e.g., IKVM)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;How it works:&lt;/strong&gt; Instead of running a JVM, a static or build-time compiler translates Java &lt;code&gt;.class&lt;/code&gt; files (bytecode) directly into .NET Common Intermediate Language (CIL) assemblies.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Upside:&lt;/strong&gt; Once compiled, everything runs natively on the .NET CLR. You do not need to ship or manage a JVM runtime in production.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Trade-offs:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;JVM-specific JIT optimizations do not apply, since the code runs on the CLR.&lt;/li&gt;
&lt;li&gt;Support follows the Java API surface implemented by the project (IKVM 8 targets Java 8).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  2. Proxy Generation &amp;amp; Shared Memory / TCP (e.g., JNBridgePro)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;How it works:&lt;/strong&gt; A proxy generator inspects your Java JARs (or .NET DLLs) at development time and generates matching wrapper classes. At runtime, a bridge engine marshals calls between the CLR and JVM using either shared memory (same process) or TCP sockets (cross-process or cross-machine).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Upside:&lt;/strong&gt; Established tooling with strong API fidelity and support for both same-process and cross-machine topologies.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Trade-offs:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Proxy assemblies need to be regenerated whenever the underlying Java or .NET APIs change.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://dev.to/jnbridge/java-c-bridge-every-integration-tool-ranked-for-2026-4cnl"&gt;As reported by the vendor&lt;/a&gt;, shared-memory calls take roughly 0.01–0.1 ms (10–100 µs) and TCP calls 0.1–1 ms.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. Direct In-Process JNI Bridging (e.g., JCOBridge)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;How it works:&lt;/strong&gt; Rather than translating bytecode or introducing intermediate serialization protocols, &lt;a href="https://jcobridge.com" rel="noopener noreferrer"&gt;JCOBridge&lt;/a&gt; loads the JVM and the .NET CLR inside the same process and connects them directly over the &lt;strong&gt;Java Native Interface (JNI)&lt;/strong&gt;—with zero code injection and no external network channels.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Upside:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sub-microsecond performance:&lt;/strong&gt; Direct method invocations run in roughly 0.1–0.5 µs depending on the call and the CPU, while filtered JVM-to-.NET event callbacks can discard unneeded events in &lt;strong&gt;30–45 nanoseconds&lt;/strong&gt;—comparable to raw JNI overhead. &lt;code&gt;ReadOnlySpan&amp;lt;T&amp;gt;&lt;/code&gt; access to &lt;code&gt;DirectByteBuffer&lt;/code&gt; data is zero-copy.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Broad runtime compatibility:&lt;/strong&gt; Supports &lt;strong&gt;Java 8 through Java 25&lt;/strong&gt; and &lt;strong&gt;.NET Framework 4.6.2+ through .NET 10 and .NET 11&lt;/strong&gt; across Windows, Linux, and macOS. You can run legacy Java 8 bytecode inside a modern JVM alongside modern .NET without touching a line of Java code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic + Reflected workflows:&lt;/strong&gt; You can invoke Java/CLR APIs dynamically without build-time proxy generation, or use pre-built/custom reflected libraries when you want full IntelliSense and strong typing.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Trade-offs:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Strictly in-process (both runtimes live in the same OS process). If you need cross-machine distribution, you pair it with a messaging layer like Kafka.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Architectural Comparison
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Dimension&lt;/th&gt;
&lt;th&gt;Bytecode Transpilation (IKVM)&lt;/th&gt;
&lt;th&gt;Proxy + Shared Memory (JNBridgePro)&lt;/th&gt;
&lt;th&gt;Direct JNI Bridge (JCOBridge)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Runtime Model&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;CLR only&lt;/td&gt;
&lt;td&gt;JVM + CLR (Shared Mem / TCP)&lt;/td&gt;
&lt;td&gt;JVM + CLR (same process via JNI)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Needs a JVM at runtime&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Typical Call Latency&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Native CLR execution&lt;/td&gt;
&lt;td&gt;10 – 100 µs (shared memory, &lt;a href="https://dev.to/jnbridge/java-c-bridge-every-integration-tool-ranked-for-2026-4cnl"&gt;as reported by the vendor&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;0.1 – 0.5 µs&lt;/strong&gt; (&lt;a href="https://jnet.masesgroup.com/articles/performance.html" rel="noopener noreferrer"&gt;our published benchmarks&lt;/a&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Seeing Direct JNI Bridging in Action
&lt;/h2&gt;

&lt;p&gt;One of the best ways to evaluate a bridge architecture is to look at real-world libraries built on top of it. Several open-source suites use JCOBridge as their underlying engine:&lt;/p&gt;

&lt;h3&gt;
  
  
  Calling Java from C# (&lt;a href="https://github.com/masesgroup/JNet" rel="noopener noreferrer"&gt;JNet&lt;/a&gt;)
&lt;/h3&gt;

&lt;p&gt;Instead of writing glue code, JNet exposes standard JDK APIs—including Java generics—directly in C# syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;Java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Util&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Instantiates a real JVM ArrayList inside the .NET process&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ArrayList&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello from .NET 10"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Running on JVM 25"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Calling .NET from Java, Scala, Clojure or Kotlin (&lt;a href="https://github.com/masesgroup/JCOReflector" rel="noopener noreferrer"&gt;JCOReflector&lt;/a&gt;)
&lt;/h3&gt;

&lt;p&gt;The same engine works in reverse. JCOReflector reflects .NET assemblies into standard Maven JARs so JVM languages can instantiate .NET classes and generics natively:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;collections&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;generic&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;List_1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nc"&gt;List_1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;List_1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Count from .NET CLR: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_Count&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Full Ecosystem Suites
&lt;/h3&gt;

&lt;p&gt;Because the bridge works without protocol translation, entire Java ecosystems can be brought into .NET without re-implementing wire protocols:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://github.com/masesgroup/KNet" rel="noopener noreferrer"&gt;KNet&lt;/a&gt;:&lt;/strong&gt; Full Apache Kafka client, Streams, and Connect SDKs for .NET (plus &lt;a href="https://github.com/masesgroup/KEFCore" rel="noopener noreferrer"&gt;KEFCore&lt;/a&gt;, an Entity Framework Core provider backed by Kafka).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://github.com/masesgroup/PLCOnNet" rel="noopener noreferrer"&gt;PLCOnNet&lt;/a&gt;:&lt;/strong&gt; Industrial PLC communication for .NET powered by Apache PLC4X.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://github.com/masesgroup/NetPDF" rel="noopener noreferrer"&gt;NetPDF&lt;/a&gt;:&lt;/strong&gt; Full Apache PDFBox capabilities in C#.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Benchmark methodology, environments, and results are publicly documented on the &lt;a href="https://jnet.masesgroup.com/articles/performance.html" rel="noopener noreferrer"&gt;JNet performance page&lt;/a&gt;, and the CI test matrices (platforms, .NET frameworks, JDK versions and vendors) are visible in the repositories.&lt;/p&gt;




&lt;h2&gt;
  
  
  Which Approach Should You Choose?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Choose REST or gRPC&lt;/strong&gt; if your Java and .NET components are independent microservices that scale separately and can tolerate millisecond-level network latency.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Choose Bytecode Transpilation (IKVM)&lt;/strong&gt; if you want to use a Java library directly on the CLR and you cannot deploy a JVM.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Choose Direct JNI Bridging (JCOBridge)&lt;/strong&gt; if you need &lt;strong&gt;sub-microsecond latency&lt;/strong&gt;, &lt;strong&gt;high-throughput streaming/callbacks&lt;/strong&gt;, compatibility with &lt;strong&gt;Java 8 through 25&lt;/strong&gt;, or bidirectional interoperability between modern .NET and the JVM without maintaining serialization layers.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;em&gt;Disclosure: I'm responsible for the company behind JCOBridge and these projects.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>csharp</category>
      <category>dotnet</category>
      <category>integration</category>
    </item>
    <item>
      <title>WPF, WinForms and AWT/Swing side-by-side</title>
      <dc:creator>Mario Mastrodicasa</dc:creator>
      <pubDate>Thu, 26 Nov 2026 00:08:44 +0000</pubDate>
      <link>https://dev.to/mario_mastrodicasa/wpf-winforms-and-awtswing-side-by-side-oen</link>
      <guid>https://dev.to/mario_mastrodicasa/wpf-winforms-and-awtswing-side-by-side-oen</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwxt501n0tnqiqlbi3hf3.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwxt501n0tnqiqlbi3hf3.jpeg" alt="Photo by KNXRT on Unsplash" width="800" height="933"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In a previous article I spoke about some features and use cases of JNet. The example in the article shown a basic example to use an AWT User Interface from a .NET console application.&lt;/p&gt;

&lt;p&gt;However .NET, especially on Windows, is not only console, it supports graphics too. In this article I’m going to discuss about the integration of some .NET and JVM UI Frameworks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why someone need this feature?
&lt;/h2&gt;

&lt;p&gt;The answer to the question can be found in some daily work. The reader could answer: I don’t need this feature, I’ll create the UI using the framework I love. However this is not possible in all conditions you can found at work. I try to explain better with some use cases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  My customer have a ready made AWT/Swing based UI, however the evolution of the project needs to use .NET. I can save time and money integrating them and avoiding the porting of AWT/Swing UI.&lt;/li&gt;
&lt;li&gt;  My customer has a .NET based UI and I have ready made AWT/Swing UI components. I can integrate my components in the customer UI with little effort. The same can be done if the customer has a Java based UI and I have ready made .NET UI components.&lt;/li&gt;
&lt;li&gt;  I have to manage the integration of components from multiple stakeholders: each stakeholder can use its preferred technology, no problem in integration.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I listed some usages of this feature, however many other possible cases can come from real world.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to integrate both UI frameworks?
&lt;/h2&gt;

&lt;p&gt;The integration happens behind the scene, the user needs to give few information to JNet and everything is done.&lt;/p&gt;

&lt;p&gt;I’m entering better in the code to show something.&lt;/p&gt;

&lt;h3&gt;
  
  
  The glue
&lt;/h3&gt;

&lt;p&gt;The real glue between both UIs is behind the scene: the user just need to use the &lt;a href="https://github.com/masesgroup/JNet/blob/44acc282db09b92ddad136faa7bd0eacdefdbff4/src/net/JNet/Java/Awt/Container.cs#L42" rel="noopener noreferrer"&gt;&lt;strong&gt;&lt;em&gt;CreateHostedContainer&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt; method available in each class extending an AWT &lt;a href="https://github.com/masesgroup/JNet/blob/44acc282db09b92ddad136faa7bd0eacdefdbff4/src/net/JNet/Java/Awt/Container.cs" rel="noopener noreferrer"&gt;Container&lt;/a&gt; class.&lt;/p&gt;

&lt;p&gt;A snippet like the following shows how to connect both UI worlds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="nc"&gt;MyJavaUIToBeIntegrated&lt;/span&gt; &lt;span class="n"&gt;javaUserUI&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;MyJavaUIToBeIntegrated&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Container&lt;/span&gt; &lt;span class="n"&gt;javaContainer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;object&lt;/span&gt; &lt;span class="n"&gt;netUIComponent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;javaContainer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Panel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;javaContainer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;javaUserUI&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="cp"&gt;#if WINFORMS&lt;/span&gt;
&lt;span class="n"&gt;netUIComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;javaContainer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CreateHostedContainer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="cp"&gt;#else&lt;/span&gt;
&lt;span class="n"&gt;netUIComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;javaContainer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CreateHostedContainer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="cp"&gt;#endif&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The steps are few and simple. The objects involved are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; The class &lt;strong&gt;MyJavaUIToBeIntegrated&lt;/strong&gt; represents the UI interface written in Java. &lt;em&gt;javaUserUI&lt;/em&gt; represents an instance of &lt;strong&gt;MyJavaUIToBeIntegrated&lt;/strong&gt;. &lt;strong&gt;MyJavaUIToBeIntegrated&lt;/strong&gt; can be any UI element: from a pre-made UI available in your JAR, or a programmatically written UI; in the test examples, or templates, of the &lt;a href="https://github.com/masesgroup/JNet" rel="noopener noreferrer"&gt;JNet repository&lt;/a&gt; the UI is made programmatically;&lt;/li&gt;
&lt;li&gt; The variable &lt;em&gt;javaContainer&lt;/em&gt; represents the &lt;strong&gt;Container&lt;/strong&gt; of the Java UI will connect both UI worlds;&lt;/li&gt;
&lt;li&gt; The variable &lt;em&gt;netUIComponent&lt;/em&gt; represents the .NET graphical object (WPF Control or WinForms Control) to be inserted into .NET UI layout.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The UI integration needs only 3 steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Build the &lt;em&gt;javaContainer&lt;/em&gt; using a &lt;a href="https://github.com/masesgroup/JNet/blob/44acc282db09b92ddad136faa7bd0eacdefdbff4/src/net/JNet/Generated/Java/Awt/AllPackageClasses.cs#LL4068C30-L4068C30" rel="noopener noreferrer"&gt;&lt;strong&gt;Panel&lt;/strong&gt;&lt;/a&gt;: &lt;strong&gt;Panel&lt;/strong&gt; inherits from &lt;strong&gt;Container&lt;/strong&gt; and has its own characteristic. The user can choose any kind of class, the main requirement is that &lt;em&gt;javaContainer&lt;/em&gt; shall be a &lt;strong&gt;Container&lt;/strong&gt; or shall have &lt;strong&gt;Container&lt;/strong&gt; has superclass.&lt;/li&gt;
&lt;li&gt; Insert &lt;em&gt;javaUserUI&lt;/em&gt; within the &lt;strong&gt;Panel&lt;/strong&gt; instance*&lt;em&gt;:&lt;/em&gt;* executed in .NET, but the final stage happens within the JVM like any other UI integration can be made in Java.&lt;/li&gt;
&lt;li&gt; Call &lt;strong&gt;&lt;em&gt;CreateHostedContainer&lt;/em&gt;&lt;/strong&gt; to obtain the object usable from .NET for graphical integration;&lt;/li&gt;
&lt;li&gt; Insert &lt;em&gt;netUIComponent&lt;/em&gt; within the .NET UI layout like any other WPF/WinForms Control.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The previous steps create only the graphical integration and both UIs runs alone (message pump are isolated). To integrate them you can use method invocation (from .NET to JVM) and callbacks (from JVM to .NET).&lt;/p&gt;

&lt;h3&gt;
  
  
  The simple example result
&lt;/h3&gt;

&lt;p&gt;As mentioned before, within the &lt;a href="https://github.com/masesgroup/JNet" rel="noopener noreferrer"&gt;JNet repository&lt;/a&gt;, there are some examples of UI integration; here some screenshot of the results obtained running the examples:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsxyrs0c6gfptw8ns2ip4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fsxyrs0c6gfptw8ns2ip4.png" alt="WPF application hosting AWT graphic" width="779" height="423"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above picture shows a simple AWT layout (&lt;strong&gt;TextArea&lt;/strong&gt; + &lt;strong&gt;Button&lt;/strong&gt;) nested into a WPF application. Pressing the AWT &lt;strong&gt;Button&lt;/strong&gt;, the WPF hosting application receives a trigger, reads the content of the &lt;strong&gt;TextArea&lt;/strong&gt; and put the value in the corresponding &lt;strong&gt;TextBox&lt;/strong&gt; of the WPF application.&lt;/p&gt;

&lt;p&gt;The following picture, instead, shows a Swing based UI integrated within the same .NET application of the previous example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fizg7gc5dvhx4ucvjf10n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fizg7gc5dvhx4ucvjf10n.png" alt="WPF application hosting Swing graphic" width="735" height="483"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What’s next step?
&lt;/h3&gt;

&lt;p&gt;I spoke about integration and shown the result. I used the simple examples found in the &lt;a href="https://github.com/masesgroup/JNet" rel="noopener noreferrer"&gt;repository&lt;/a&gt; so anyone can reproduce them without problems. When the logic behind is well known the examples can be extended, or replaced, with your own graphic to verify the effectiveness of the approach. Attaching events on your AWT/Swing graphic objects you can fully integrate it with the hosting .NET application, or if you don’t need feedback from JVM, you can simply invokes methods on the JVM objects from .NET.&lt;/p&gt;

&lt;p&gt;Everything depends on your needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In this article I discussed about the integration of the .NET and JVM graphics. It is the continuation and extension of the previous article where JNet was presented the first time. Both articles, this and the previous one, demonstrate how simple is the usage of JVM from .NET using JNet. I have reported some use cases, however there are other possible usage I can’t imagine 😉.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>java</category>
      <category>wpf</category>
    </item>
    <item>
      <title>JNet in 2026: the JVM and .NET, side by side — three years later</title>
      <dc:creator>Mario Mastrodicasa</dc:creator>
      <pubDate>Wed, 25 Nov 2026 23:58:56 +0000</pubDate>
      <link>https://dev.to/mario_mastrodicasa/jnet-in-2026-the-jvm-and-net-side-by-side-three-years-later-ieb</link>
      <guid>https://dev.to/mario_mastrodicasa/jnet-in-2026-the-jvm-and-net-side-by-side-three-years-later-ieb</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy6l2piy4g2aw3jtfn8z7.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fy6l2piy4g2aw3jtfn8z7.jpeg" alt="Photo by Timo Volz on Unsplash" width="800" height="534"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by Timo Volz on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is a follow-up to&lt;/em&gt; &lt;a href="https://dev.to/mario_mastrodicasa_791193/java-apis-written-in-c-jvm-and-net-side-by-side-31bk"&gt;&lt;em&gt;Java APIs written in C# — JVM and .NET side by side&lt;/em&gt;&lt;/a&gt;&lt;em&gt;. If you are new to JNet, start there.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Three years ago I wrote about JNet — a project that runs a real JVM inside your .NET process and exposes its entire API surface to C#. The core idea has not changed: no byte-code conversion, no TCP channel, no intermediate layer. One process, two runtimes, one boundary.&lt;/p&gt;

&lt;p&gt;What &lt;em&gt;has&lt;/em&gt; changed is everything around that boundary: how fast it is, how much control you have over it, and what you can do with bulk data crossing it. This article covers what is new.&lt;/p&gt;
&lt;h3&gt;
  
  
  The ecosystem today
&lt;/h3&gt;

&lt;p&gt;When the first article was published, JNet was essentially a library and a code generator. Today it is the foundation of a larger suite:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;JNet&lt;/strong&gt;  — the core library. Almost the full Java API surface, plus any JVM language through JNetReflector.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JNetReflector&lt;/strong&gt;  — points at any JAR and produces production-ready C# classes. In 2023 it was still maturing; today it generates everything: generics, nested types, default and static interface methods, listener wiring, Dispose patterns.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;KNet&lt;/strong&gt;  — Apache Kafka APIs for .NET, built entirely on JNet. See the &lt;a href="https://dev.to/mario_mastrodicasa_791193/knet-a-new-way-to-use-apache-kafka-from-net-b33"&gt;dedicated article&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;KEFCore&lt;/strong&gt;  — Entity Framework Core provider for Apache Kafka, built on KNet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JNetPS&lt;/strong&gt; and &lt;strong&gt;JNetCLI&lt;/strong&gt;  — PowerShell and REPL interfaces to the JVM.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;JNetReflector is the common thread. It does the work that used to require manual effort — and now does it well enough that KNet and JNet themselves are generated from it.&lt;/p&gt;
&lt;h3&gt;
  
  
  JNetReflector: from scaffolding tool to full generator
&lt;/h3&gt;

&lt;p&gt;In 2023 the article mentioned JNetReflector as a promising tool. Today it is the backbone of the entire suite.&lt;/p&gt;

&lt;p&gt;Point it at a JAR:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;JNetReflector -SourceJar mylib.jar -OutputDirectory ./generated
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What comes out is not a skeleton. It is complete, compilable C# — including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Listeners and callbacks&lt;/strong&gt; with full wiring: the generated class already handles the JVM→.NET event path, delegate registration, and the new two-gate filter (see below).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generics&lt;/strong&gt;  — including raw-type companions for cases where the concrete type is only known at runtime.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dispose pattern&lt;/strong&gt; with Interlocked-based thread safety.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;InvokeWithSignature&lt;/strong&gt; where the JNI signature is statically known — lower overhead, validation delegated to the JVM.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The original article showed AWT Button as an example. Here is what JNetReflector generates for a listener today — compare with writing it by hand:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Generated by JNetReflector — no manual work required&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;partial&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ActionListener&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Util&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;EventListener&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;IActionListener&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Constructor caches whether ListenerShallManageEvent(int, object) is overridden&lt;/span&gt;
    &lt;span class="c1"&gt;// in a subclass — avoids per-event reflection cost at runtime.&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;ActionListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;params&lt;/span&gt; &lt;span class="k"&gt;object&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;base&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// First gate - evaluated in order:&lt;/span&gt;
    &lt;span class="c1"&gt;// 1. ListenerShallManageEventIndex delegate (index-based, no string conversion)&lt;/span&gt;
    &lt;span class="c1"&gt;// 2. ListenerShallManageEventName delegate (resolves name via ConvertListenerEventIndexToEventName)&lt;/span&gt;
    &lt;span class="c1"&gt;// 3. ListenerShallManageEventHandlers - true if any handler is registered for this index&lt;/span&gt;
    &lt;span class="c1"&gt;// 4. Falls through to second gate if override detected or WithData delegates are set&lt;/span&gt;
    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nc"&gt;ListenerShallManageEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;eventIndex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="c1"&gt;// ActionPerformed: exposed as both a delegate and a virtual method.&lt;/span&gt;
    &lt;span class="c1"&gt;// The delegate takes precedence if assigned; otherwise the virtual is called.&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Action&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Awt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;EventNs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ActionEvent&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;OnActionPerformed&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;virtual&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;ActionPerformed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Awt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;EventNs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ActionEvent&lt;/span&gt; &lt;span class="n"&gt;arg0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The listener works out of the box. The filter hooks are there when you need them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Controlling what crosses the boundary: the two-gate filter
&lt;/h3&gt;

&lt;p&gt;Every JVM→.NET callback has a cost. When a JVM source fires many event types — an AWT component, a Kafka Streams topology, an OPC-UA subscription — most events may have no registered handler on the .NET side. Without filtering, each event still pays the full cost of argument retrieval and type conversion before being discarded.&lt;/p&gt;

&lt;p&gt;JNet 2.6.7+ introduced ListenerShallManageEvent: two virtual methods (and delegate equivalents) that intercept events before data is read.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;JVM fires event
       │
       ▼
First gate — ListenerShallManageEvent(int eventIndex)
  false → discard immediately, no data read ~30–35 ns
  true ─────────────────────────────────────────────────┐
                                                         ▼
                               Second gate — ListenerShallManageEvent(int eventIndex, object data)
                                 false → discard, no handler invoked ~144–152 ns
                                 true ──────────────────────────────────────────────────────┐
                                                                                             ▼
                                                                              Full handler invocation
                                                                                       ~2.7 µs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The fastest path uses ListenerShallManageEventIndex — it receives the raw integer event index with no string conversion:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;listener&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ActionListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// First gate: only process actionPerformed (index 0), discard all others&lt;/span&gt;
&lt;span class="n"&gt;listener&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ListenerShallManageEventIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;eventIndex&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;eventIndex&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// Second gate: inspect raw data before committing to full processing&lt;/span&gt;
&lt;span class="n"&gt;listener&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ListenerShallManageEventIndexWithData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;eventIndex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// data is CLRListenerEventArgs - cast and inspect without full conversion&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;ShouldProcess&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;listener&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ActionPerformed&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ActionCommand&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or via virtual override in a subclass — JNetReflector handles the wiring either way.&lt;/p&gt;

&lt;h3&gt;
  
  
  Performance: numbers from the boundary
&lt;/h3&gt;

&lt;p&gt;All numbers below are from GitHub Actions (ubuntu-22.04, AMD EPYC 9V45), 1 000 000 iterations, JCOBridge 2.6.9. Full tables on the &lt;a href="https://masesgroup.github.io/JNet/articles/performance.html" rel="noopener noreferrer"&gt;JNet performance page&lt;/a&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Method invocation
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Scenario Invoke InvokeWithSig Invoke InvokeWithSig
                     fb=false fb=false fb=true fb=true
------------------------------------------------------------------------------
Static (.NET 8) 0.313 µs 0.248 µs 0.471 µs 0.311 µs
Instance (.NET 8) 0.189 µs 0.162 µs 0.389 µs 0.287 µs
Static (.NET 10) 0.265 µs 0.250 µs 0.482 µs 0.305 µs
Instance (.NET 10) 0.176 µs 0.178 µs 0.390 µs 0.307 µs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instance method invocation with InvokeWithSignature reaches &lt;strong&gt;162 ns&lt;/strong&gt; on .NET 8 and &lt;strong&gt;178 ns&lt;/strong&gt; on .NET 10 — down from ~468 ns in 2.6.6, a &lt;strong&gt;−65%&lt;/strong&gt; reduction over two years.&lt;/p&gt;

&lt;h4&gt;
  
  
  Callback (JVM → .NET, sustained stream)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Path .NET 8 .NET 10
---------------------------------------------------------------------
Full processing 2.674 µs 2.750 µs
First gate discard 0.035 µs 0.030 µs
(ListenerShallManageEventIndex)

Second gate discard 0.144 µs 0.152 µs
(raw data inspected)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first-gate discard at &lt;strong&gt;30–35 ns&lt;/strong&gt; is within the range of raw JNI overhead measured on dedicated hardware — despite the additional CLR interop layer and a shared CI runner.&lt;/p&gt;

&lt;h4&gt;
  
  
  Where the improvement came from
&lt;/h4&gt;

&lt;p&gt;The largest single gain in 2.6.9 came from a simple structural fix: an internal buffer used by the dispose fast-scope path was previously allocated on every event. Making it a pooled, thread-local resource that survives across scopes eliminated ~1M array allocations per test and reduced total test time from ~23s to ~14s.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bulk data: reading JVM memory from .NET
&lt;/h3&gt;

&lt;p&gt;When a JVM method returns an array — audio samples, sensor readings, a Kafka record payload — the standard path copies that array across the JNI boundary into a new .NET byte[]. For large payloads this copy dominates.&lt;/p&gt;

&lt;p&gt;JCOBridge 2.6.9 introduces two typed wrappers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;JCOBridgeStream&lt;/strong&gt;  — wraps a JVM native array. Exposes UnmanagedMemoryStream, ReadOnlySpan, and .NET Framework-compatible shims.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JCOBridgeDirectBuffer&lt;/strong&gt;  — wraps a JVM DirectByteBuffer. Same surface. Because a DirectByteBuffer lives in native (off-heap) memory, AsSpan() is &lt;strong&gt;zero-copy in all editions&lt;/strong&gt;  — no HPA required.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;JNetReflector does not generate xxxStream() variants for every method — the limitation is fundamental: with a generic type like Map, the concrete array type of V is only known at runtime. Instead, you obtain JCOBridgeStream from the &lt;strong&gt;raw type&lt;/strong&gt; companion that JNetReflector generates alongside every generic:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Via Convert&amp;lt;T&amp;gt;() extension on the raw return value&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// object (raw type)&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;JCOBridgeStream&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;stream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Convert&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;JCOBridgeStream&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;ReadOnlySpan&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;span&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AsSpan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// zero-copy with HPA&lt;/span&gt;
&lt;span class="c1"&gt;// Or via IJavaArray.ToStream&amp;lt;T&amp;gt;()&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Value&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;IJavaArray&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;JCOBridgeStream&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;stream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToStream&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;FileAccess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Read&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside a listener’s second gate, the same pattern lets you inspect array contents before deciding whether to invoke the handler:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nc"&gt;ListenerShallManageEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;eventIndex&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;object&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;CLRListenerEventArgs&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;JNetEventResult&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;IJavaObject&lt;/span&gt; &lt;span class="n"&gt;firstParam&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;EventData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;firstParam&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;IJavaArray&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;firstParam&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToJavaArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;JCOBridgeStream&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;stream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToStream&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;ReadOnlySpan&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;byte&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;span&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AsSpan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;ShouldProcess&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;span&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// inspect without allocating a .NET array&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Performance (100 iterations, ubuntu-22.04)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;API 1 KB 1 MB 100 MB
----------------------------------------------------------------------
Invoke&amp;lt;byte[]&amp;gt; (copy) 2.7 µs 205.9 µs 14,635.8 µs
JCOBridgeStream / AsSpan 2.6 µs 214.9 µs 14,384.0 µs
DirectByteBuffer / AsSpan 2.7 µs 31.1 µs 5,590.3 µs
DirectByteBuffer / ToStream naive 6.5 µs 608.1 µs 38,873.0 µs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;DirectByteBuffer + AsSpan reaches &lt;strong&gt;17.9 GB/s&lt;/strong&gt; at 100 MB. The naive MemoryStream pattern is 7× slower at 100 MB — avoid it.&lt;/p&gt;

&lt;h3&gt;
  
  
  HPA and zero-copy for JVM arrays
&lt;/h3&gt;

&lt;p&gt;JCOBridgeStream with the standard edition still makes an internal copy. With the &lt;strong&gt;HPA edition&lt;/strong&gt; , AsSpan() accesses JVM array memory directly — GC pinned for the duration, no copy. Check JCOBridge.IsHPAEdition at startup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;JCOBridge&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;IsHPAEdition&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// AsSpan() on JCOBridgeStream&amp;lt;T&amp;gt; is truly zero-copy&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The DirectByteBuffer benchmark (pre-allocated native memory, no heap→native copy) shows what HPA-level performance looks like for array access — the same absence of copy that HPA achieves for JVM arrays.&lt;/p&gt;

&lt;h3&gt;
  
  
  What has not changed
&lt;/h3&gt;

&lt;p&gt;The foundation is the same as in 2023:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One JVM per process, started at CreateGlobalInstance().&lt;/li&gt;
&lt;li&gt;No marshalling, no TCP, no byte-code conversion.&lt;/li&gt;
&lt;li&gt;The JVM you choose — Temurin, GraalVM, Azul — with the version you need.&lt;/li&gt;
&lt;li&gt;AWT/Swing still works, still embeddable in WinForms and WPF.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The AWT example from the original article compiles and runs unchanged today.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where to go from here
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Performance details&lt;/strong&gt; : &lt;a href="https://masesgroup.github.io/JNet/articles/performance.html" rel="noopener noreferrer"&gt;JNet performance page&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bulk data and&lt;/strong&gt;  &lt;strong&gt;ListenerShallManageEvent&lt;/strong&gt; : &lt;a href="https://masesgroup.github.io/JNet/articles/performancetips.html" rel="noopener noreferrer"&gt;JNet performance tips&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Apache Kafka from .NET&lt;/strong&gt; : &lt;a href="https://dev.to/mario_mastrodicasa_791193/knet-a-new-way-to-use-apache-kafka-from-net-b33"&gt;KNet article&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Entity Framework Core on Kafka&lt;/strong&gt; : KEFCore articles on Medium — &lt;a href="https://medium.com/@mario.mastrodicasa/kefcore-apache-kafka-provider-for-entity-framework-core-465911ef82b5" rel="noopener noreferrer"&gt;introduction&lt;/a&gt;, &lt;a href="https://medium.com/@mario.mastrodicasa/entity-framework-core-provider-for-apache-kafka-how-it-works-and-use-cases-80be6cd37c66" rel="noopener noreferrer"&gt;how it works and use cases&lt;/a&gt;, &lt;a href="https://medium.com/@mario.mastrodicasa/entity-framework-core-provider-for-apache-kafka-performance-5db2edbe2eed" rel="noopener noreferrer"&gt;performance&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JNet on GitHub&lt;/strong&gt; : &lt;a href="https://github.com/masesgroup/JNet" rel="noopener noreferrer"&gt;masesgroup/JNet&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JCOBridge HPA edition&lt;/strong&gt; : &lt;a href="https://www.jcobridge.com" rel="noopener noreferrer"&gt;jcobridge.com&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Benchmark environment: GitHub Actions&lt;/em&gt; &lt;em&gt;ubuntu-22.04, AMD EPYC 9V45 96-Core, JCOBridge 2.6.9, 1 000 000 iterations. Full methodology and tables at the link above.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>opensource</category>
      <category>performance</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Java APIs written in C#: JVM and .NET side-by-side</title>
      <dc:creator>Mario Mastrodicasa</dc:creator>
      <pubDate>Wed, 25 Nov 2026 23:56:18 +0000</pubDate>
      <link>https://dev.to/mario_mastrodicasa/java-apis-written-in-c-jvm-and-net-side-by-side-31bk</link>
      <guid>https://dev.to/mario_mastrodicasa/java-apis-written-in-c-jvm-and-net-side-by-side-31bk</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpp3qazwauqca5c7athc1.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpp3qazwauqca5c7athc1.jpeg" alt="Photo by Perry Kibler on Unsplash" width="800" height="1199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this article I present another way to use any &lt;a href="https://en.wikipedia.org/wiki/List_of_JVM_languages" rel="noopener noreferrer"&gt;JVM enabled language&lt;/a&gt; from .NET: the project &lt;a href="https://github.com/masesgroup/JNet" rel="noopener noreferrer"&gt;JNet&lt;/a&gt;, hosted on GitHub. The project exposes almost the full API surface of Java 8 to any .NET user, but not only this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a project like this?
&lt;/h2&gt;

&lt;p&gt;The answer to the question is in the history of another project: &lt;a href="https://github.com/masesgroup/KNet" rel="noopener noreferrer"&gt;KNet&lt;/a&gt;. KNet is the porting of the &lt;a href="http://kafka.apache.org" rel="noopener noreferrer"&gt;Apache Kafka&lt;/a&gt; Java APIs to .NET and I will write deeply on it in another article. Well, originally the first project done was KNet and Apache Kafka Java APIs were written in C# with a big developing effort. Looking in the code many classes used from Apache Kafka are the one of the JVM used to run it. So the idea was to move the Java classes to a new project dedicated to that scope and use it as dependency of KNet. The first incubation of JNet was done using the classes used from KNet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Evolution
&lt;/h2&gt;

&lt;p&gt;The first published package was very poor, however many needs were discovered and the roadmap was updated with other features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  A command line interface (JNetCLI) was added to interact with the underlying library in many ways: REPL and scripts written in C# that interact with the JVM.&lt;/li&gt;
&lt;li&gt;  An extension to PowerShell (JNetPS) to interact with the JVM using PowerShell scripting language.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Anyway, the core library (JNet) was always manually made with a big development effort. So the last, but not least, project added is JNetReflector: a tool able to use the reflection to write the C# classes corresponding to the one in JVM.&lt;/p&gt;

&lt;p&gt;With JNetReflector the effort to build the C# classes was reduced and JNet now contains almost the full API surface of Java 11. Since JNetReflector use the reflection it is able to reflect any language based on the JVM like Scala, Kotlin and so on.&lt;/p&gt;

&lt;p&gt;Now the project motto is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;.NET suite for Java™/JVM™&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What can be done with JNet?
&lt;/h2&gt;

&lt;p&gt;There are many ways to use JNet, here a non exhaustive list from the current usages. I try to divide it based on the specific project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;JNet&lt;/strong&gt;: this is the core library and it can be integrated within other .NET project to use directly the JVM APIs. The core library itself can be used to interact with any class in JVM using the features available and described in &lt;a href="https://github.com/masesgroup/JNet/blob/master/src/net/Documentation/articles/API_extensibility.md" rel="noopener noreferrer"&gt;API extensibility&lt;/a&gt; article. Currently, KNet project use the library to avoid generation of Java APIs. Other features available are related to the graphical components of Java (AWT/Swing): they can be allocated standalone from .NET or integrated within .NET based User Interfaces: for anyone curious the templates contains usage examples about this features.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;JNetPS&lt;/strong&gt;: the project contains some basic cmdlet to instantiate JVM classes and use them, plus many specific cmdlet targeting JMX. This can help any user of PowerShell to interact with the JMX APIs to retrieve information and use it within PowerShell scripts.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;JNetCLI&lt;/strong&gt;: could be used to interact with the JVM from any command prompt with REPL, C# scripts or can load code files to be executed mixing C# and requests to JVM.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;JNetReflector&lt;/strong&gt;: currently it is used to generate the reflected classes of the JNet core library, and there is a specific task to use it to fully regenerate the classes manually made in KNet project. Anyway, any user can use it to reflect the classes of any JAR he wants to use from .NET. Think about a JAR (maybe some package from any Maven repository, e.g. &lt;a href="https://central.sonatype.com/?smo=true" rel="noopener noreferrer"&gt;Maven Central&lt;/a&gt;) or a project made in Java we want to use from .NET. It can be possible to use directly JNet and its &lt;a href="https://github.com/masesgroup/JNet/blob/master/src/net/Documentation/articles/API_extensibility.md" rel="noopener noreferrer"&gt;API extensibility&lt;/a&gt;, anyway JNetReflector comes to help us: just launch the tool targeting the JAR and the .NET code is ready for you. The last is the option will be used from KNet to reflect the Java APIs of Apache Kafka: this approach guarantee that any update on the JAR can be immediately reported to .NET; with an automatic pipeline any upgrade of the JAR (e.g. someone updates or improves the Maven package) can be converted into .NET code with a limited effort.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The way JNet works
&lt;/h2&gt;

&lt;p&gt;JNet interacts with the JVM and does not rewrite it. What does it means? When a JVM API is invoked from C#, the code is executed in the real JVM running within the .NET process. Behind the scene: during .NET process initialization a JVM is started within the .NET process. Both .NET and JVM lives alone with their own threads, Garbage Collector and so on, but can interact together: JNet invokes the JVM methods, while JVM can send back events to .NET.&lt;/p&gt;

&lt;h3&gt;
  
  
  Benefits and drawbacks
&lt;/h3&gt;

&lt;p&gt;The approach followed from JNet guarantee multiple benefits than other solutions available with some possible drawbacks. I try to list some of them:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Runtime identification&lt;/strong&gt;: methods and fields in JVM classes are identified at runtime and not linked at compile-time; when a method is invoked the first time, JNet needs a longer time-slot to identify the method, then it is cached for subsequent invocation; this behavior allows to use JVM classes even if they are unknown till their invocation and it is the principle behind &lt;a href="https://github.com/masesgroup/JNet/blob/master/src/net/Documentation/articles/API_extensibility.md" rel="noopener noreferrer"&gt;API extensibility&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;In-process communication&lt;/strong&gt;: JVM and .NET communicate within the same process and this guarantee that the communication does not need external channels (marshalling is avoided) and the attack surface is reduced to the minimum; an approach made using other kind of communication channels (like TCP in some solutions) needs marshalling and can expose the final product to cyber-attacks.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;JNet needs an external JDK/JRE to work&lt;/strong&gt;: this can be a limitation that other solutions solves with a JVM rewritten for .NET, however with this approach the user of JNet has the freedom to choose the best JVM for his needs: version, supplier and so on; furthermore JNet inherits the cybersecurity characteristics of the chosen JVM.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Direct usage&lt;/strong&gt;: continuing from the above point there is no need of byte-code to IL conversion to use the classes of JVM; this implies that JNet does not need any other intermediate layer which can be source of errors and wrong behaviors.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Just a usage example
&lt;/h2&gt;

&lt;p&gt;The repository contains some example codes. Here I put a code, taken from the available templates, which shows an AWT application that interacts with C#:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="no"&gt;MASES&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;JNetTemplate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;JNetAWTApp&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyJNetCore&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;JNetCore&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MyJNetCore&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Program&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;MyJNetCore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CreateGlobalInstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// this call prepares the environment: it is mandatory to initialize the JVM&lt;/span&gt;
            &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;appArgs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MyJNetCore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FilteredArgs&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// contains the remaining arguments, the JNet and JCOBridge arguments are discarded&lt;/span&gt;
            &lt;span class="k"&gt;try&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;vApp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;JVMWrapperApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="n"&gt;vApp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Exception&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;JVMWrapperApp&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="n"&gt;execute&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;ActionDone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ActionEvent&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ActionCommand&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"writeToConsole"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Action from JVM"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ActionCommand&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"closeApplication"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Closing..."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="n"&gt;execute&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;Execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;listener&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ActionListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ActionDone&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;frame&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Frame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"My First GUI"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="n"&gt;frame&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SetSize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;buttonWrite&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Write to console"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="nc"&gt;ActionCommand&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"writeToConsole"&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="n"&gt;buttonWrite&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddActionListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;listener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;buttonClose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Close application"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="nc"&gt;ActionCommand&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"closeApplication"&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="n"&gt;buttonClose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddActionListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;listener&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;panel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Panel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;layout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;GridLayout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="n"&gt;panel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Layout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;layout&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="n"&gt;panel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;buttonWrite&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Adds Button to content pane of frame&lt;/span&gt;
                    &lt;span class="n"&gt;panel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;buttonClose&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Adds Button to content pane of frame&lt;/span&gt;
                    &lt;span class="n"&gt;frame&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;panel&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="n"&gt;frame&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SetVisible&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="nc"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Waiting for close..."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Threading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now I try to explain the above code because in my opinion it demonstrates many capabilities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The code creates a simple user interface, based on AWT, which interacts with the .NET process started it; the ability to create an User Interface is one of the features that JNet gives to its users.&lt;/li&gt;
&lt;li&gt;  After initialization, the first step is to create a listener for events from the JVM; this is another feature available in JNet: a JVM can reacts and stimulates the .NET side.&lt;/li&gt;
&lt;li&gt;  All elements of the user interface are built like it is done in any Java code, then are joined together; JNet creates JVM objects like it is done for any other .NET object, the only difference is where the instance lives.&lt;/li&gt;
&lt;li&gt;  A single listener is attached to both &lt;strong&gt;&lt;em&gt;Button&lt;/em&gt;&lt;/strong&gt; objects involved in the graphic layout built; the listener lives both in the JVM and in .NET, and it is possible to use a single instance like a Java code can do.&lt;/li&gt;
&lt;li&gt;  The JVM objects are created like it is done in C# for .NET objects: just use a simple &lt;em&gt;new&lt;/em&gt; call.&lt;/li&gt;
&lt;li&gt;  The objects in JVM can interact with the .NET code: the listener used to listen for events from JVM use a .NET callback to execute the actions in the .NET program.&lt;/li&gt;
&lt;li&gt;  The C# code is very similar to an equivalent Java code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq4t6u43kexv4859xb55t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fq4t6u43kexv4859xb55t.png" alt="The image shows the code running" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Above an image showing the code running:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  The console shows the output of the action stimulated from “Write to console” button; the trigger is in JVM (&lt;strong&gt;&lt;em&gt;Button&lt;/em&gt;&lt;/strong&gt;), the final action is in the .NET code (&lt;strong&gt;ActionDone&lt;/strong&gt; &lt;em&gt;callback&lt;/em&gt;).&lt;/li&gt;
&lt;li&gt;  The Java AWT User Interface runs alone than the hosting application made in .NET: making the example more reach, instead to loop waiting for close, the .NET side can do anything and receives events from JVM or invokes the JVM for other actions to be done.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  JVM or Java: a bit of clarification
&lt;/h2&gt;

&lt;p&gt;In the article I’m using sometime the term &lt;strong&gt;JVM&lt;/strong&gt; and sometime the term &lt;strong&gt;Java&lt;/strong&gt;. Most of the user knows the difference between them, but I want to explain why I used both. JNet and its tools interacts with the &lt;strong&gt;JVM&lt;/strong&gt; hosted in the .NET process, so generally speaking the best term to be used is &lt;strong&gt;JVM&lt;/strong&gt;. This means that JNet is able to manages every programming language supported from the &lt;strong&gt;JVM&lt;/strong&gt; and &lt;strong&gt;Java&lt;/strong&gt; is the first of all. Specifically, I used &lt;strong&gt;Java&lt;/strong&gt; when the counterpart is a class generated from Java or available in the &lt;strong&gt;Java&lt;/strong&gt; framework, like the &lt;strong&gt;&lt;em&gt;Button&lt;/em&gt;&lt;/strong&gt; class of AWT framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  JNetReflector in action
&lt;/h2&gt;

&lt;p&gt;The code reported in the article uses some classes made in JNet using JNetReflector. An example is &lt;strong&gt;&lt;em&gt;Button&lt;/em&gt;&lt;/strong&gt;&lt;em&gt;,&lt;/em&gt; which is part of the AWT framework, and its source code is available at &lt;a href="https://github.com/masesgroup/JNet/blob/master/src/net/JNet/Generated/Java/Awt/Button.cs" rel="noopener noreferrer"&gt;https://github.com/masesgroup/JNet/blob/master/src/net/JNet/Generated/Java/Awt/Button.cs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Starting from the meaning of what is the JVM, with JNetReflector it is possible to convert JVM classes (compiled from Java, Scala, Kotlin, etc) into .NET classes which reproduce them in this way:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Fields are converted into C# properties: in all cases they are readable and becomes writable if the JVM counterpart meets the right conditions;&lt;/li&gt;
&lt;li&gt;  Methods are converted into static, or instance, properties if they follow the getter/setter pattern in the JVM;&lt;/li&gt;
&lt;li&gt;  Otherwise methods becomes both static, or instance, methods of the C# class;&lt;/li&gt;
&lt;li&gt;  Generics are managed following the pattern found in Java;&lt;/li&gt;
&lt;li&gt;  Nested classes are managed as nested classes in C#.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;JNet itself represents JNetReflector in action: most of the classes available in JNet are reflected using JNetReflector, few of them (mainly classes in java.lang.* package) are manually managed because they are shared between JNet and JNetReflector.&lt;/p&gt;

&lt;p&gt;With JNetReflector every JAR, or module, can be converted into C# classes; this approach permits to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  converts the JAR into an assembly;&lt;/li&gt;
&lt;li&gt;  the original JAR, or an updated version of it, can be used without the need to regenerate the assembly each time;&lt;/li&gt;
&lt;li&gt;  there is no need to make a byte-code to IL conversion each time a new JAR is available.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Other features
&lt;/h2&gt;

&lt;p&gt;There are other features available, however I’ll simply list them, an explanation will be done in other articles dedicated to each specific topic:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  JNet supports many options to define how the JVM shall be loaded and started, from memory, to debug, to JNI, etc&lt;/li&gt;
&lt;li&gt;  The example in the article shows an AWT application built in code and running alone, however:

&lt;ul&gt;
&lt;li&gt;the same application can be integrated within a WinForms, or WPF, application as an embedded object of the hosting application: &lt;strong&gt;so .NET and AWT/Swing can interact both in graphic and in console applications&lt;/strong&gt;;&lt;/li&gt;
&lt;li&gt;an existent Java application made in AWT/Swing can be started and integrated from .NET;&lt;/li&gt;
&lt;li&gt;an existent Java application made in AWT/Swing can be integrated from a WinForms, or WPF, application.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Update — 2026&lt;/strong&gt;: Three years have passed since this article was published. JNet has evolved substantially — new performance numbers, a two-gate event filter, bulk data transfer APIs, and a much more mature JNetReflector. If you want to see where the project stands today, read the follow-up: &lt;a href="https://dev.to/mario_mastrodicasa_791193/jnet-in-2026-the-jvm-and-net-side-by-side-three-years-later-ieb"&gt;JNet in 2026: the JVM and .NET, side by side — three years later&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In the article I wrote an overview of JNet touching many points. Other article will analyze deeply some features or the usage of JNet suite from projects like KNet.&lt;/p&gt;

</description>
      <category>dotnet</category>
      <category>csharp</category>
      <category>java</category>
      <category>jvm</category>
    </item>
    <item>
      <title>Does JCOReflector make ClojureCLR superfluous?</title>
      <dc:creator>Mario Mastrodicasa</dc:creator>
      <pubDate>Tue, 20 Oct 2026 12:47:43 +0000</pubDate>
      <link>https://dev.to/mario_mastrodicasa/does-jcoreflector-make-clojureclr-superfluous-o2h</link>
      <guid>https://dev.to/mario_mastrodicasa/does-jcoreflector-make-clojureclr-superfluous-o2h</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Facstc07a7uo6fmliu3fx.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Facstc07a7uo6fmliu3fx.jpeg" width="800" height="533"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by Daniil Komov on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;ClojureCLR has been around since 2009 — a full port of the Clojure compiler and runtime that targets the CLR instead of the JVM, maintained under the Clojure Core Team umbrella alongside mainline Clojure and ClojureScript. It’s still alive: it is released together with Clojure itself, and today both sit on the same tag, clojure-1.13.0-alpha8.&lt;/p&gt;

&lt;p&gt;It exists to answer one question: &lt;em&gt;I want to write Clojure, and I need .NET.&lt;/em&gt; &lt;a href="https://github.com/masesgroup/JCOReflector" rel="noopener noreferrer"&gt;JCOReflector&lt;/a&gt; answers a version of that same question from the opposite direction — stay on the JVM, stay on mainline Clojure, and bring .NET to you instead of porting Clojure to .NET. Worth asking plainly: for people who reach for ClojureCLR today, does JCOReflector make that unnecessary?&lt;/p&gt;
&lt;h3&gt;
  
  
  Two very different ways to get there
&lt;/h3&gt;

&lt;p&gt;ClojureCLR reimplements the Clojure compiler itself to emit CIL instead of JVM bytecode. The payoff is genuine: .NET interop in ClojureCLR is &lt;em&gt;native&lt;/em&gt; Clojure interop syntax, because as far as the compiler is concerned, .NET types are the only kind of host types that exist. (.ToString obj), (System.String/Format "{0}" x) — no indirection, no generated glue, it's exactly how Clojure-on-the-JVM calls Java.&lt;/p&gt;

&lt;p&gt;The cost of that payoff is a second, parallel Clojure. Not a library — a whole separate implementation that has to track every language change mainline Clojure makes. Today the two are on the same tag, so the point is not a delay: it is that the alignment is work somebody has to keep doing, release after release. And crucially: you lose the JVM. Out of the box, a ClojureCLR program cannot reach into the Java ecosystem — Maven Central doesn’t exist from where it’s standing. The same bridge exists in the opposite direction, though: JNet generates C# bindings for JVM classes, so a .NET process can call them. Since ClojureCLR runs on a real CLR, it could in principle use JNet to reach the JVM. That route is untested here, and it means hosting a JVM next to ClojureCLR — the mirror image of what JCOReflector does.&lt;/p&gt;

&lt;p&gt;JCOReflector doesn’t touch the compiler at all. It runs ahead of time, pointed at a .NET assembly, and generates ordinary .java source — one real class per .NET type, implementing a marker interface (IJCOBridgeReflected) and carrying everything needed to round-trip across JCOBridge, the library that actually hosts a CLR instance inside the JVM process. From Clojure’s point of view, a generated class is just another Java class: no special reader-conditional, no separate dialect, no separate compiler — ordinary :clj code, ordinary (ns ... (:import ...)), ordinary Java interop that’s been stable in Clojure since 1.0. There is one exception, generic classes, and it is the interesting part.&lt;/p&gt;
&lt;h3&gt;
  
  
  What that actually looks like
&lt;/h3&gt;

&lt;p&gt;The generated API keeps .NET’s method names, PascalCase as in list.Add(x) or dict.TryGetValue(key, value), while properties and events follow the Java conventions: a property becomes a getX/setX pair (getCount()), an event an addX/removeX pair. Generic classes also need the anonymous-subclass idiom, new List_1() {} in Java, so that the type argument survives Java’s erasure. That idiom is the catch for Clojure: proxy, reify and gen-class generate classes, but none of them writes the generic signature of the superclass, so a generic class built with them looks like a raw one and the type argument is lost.&lt;/p&gt;

&lt;p&gt;The project solves it with a small helper, generics. GenericSupport/new-generic, which generates that subclass at runtime. The type argument problem and the helper are described in the &lt;a href="https://github.com/masesgroup/JCOReflector/blob/master/src/documentation/articles/generics.md" rel="noopener noreferrer"&gt;generics article&lt;/a&gt;, and the helper itself is &lt;a href="https://github.com/masesgroup/JCOReflector/blob/master/tests/jvm/clojure/src/main/clojure/generics/GenericSupport.clj" rel="noopener noreferrer"&gt;GenericSupport.clj&lt;/a&gt; in the repository.&lt;/p&gt;

&lt;p&gt;This is not an invented example: it is the test that sorts a Listwith a Comparison delegate, taken from the project’s own suite &lt;a href="https://github.com/masesgroup/JCOReflector/blob/master/tests/jvm/clojure/src/main/clojure/generics/GenericComparisonDelegateSortsAList.clj" rel="noopener noreferrer"&gt;GenericComparisonDelegateSortsAList.clj&lt;/a&gt;, trimmed of its -main and of the imports that -main uses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight clojure"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ns&lt;/span&gt; &lt;span class="nv"&gt;generics.GenericComparisonDelegateSortsAList&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:require&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;generics.GenericSupport&lt;/span&gt; &lt;span class="ss"&gt;:as&lt;/span&gt; &lt;span class="nv"&gt;gs&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:import&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;java.util.concurrent.atomic&lt;/span&gt; &lt;span class="nv"&gt;AtomicInteger&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
           &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;org.mases.jcobridge.netreflection&lt;/span&gt; &lt;span class="nv"&gt;IJCOBridgeReflected&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
           &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;system&lt;/span&gt; &lt;span class="nv"&gt;Comparison_1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
           &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;system.collections.generic&lt;/span&gt; &lt;span class="nv"&gt;List_1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;;; Exercises a generic delegate with a primitive return type (Comparison&amp;lt;T&amp;gt; returns int).&lt;/span&gt;
&lt;span class="c1"&gt;;; The delegate is a generated subclass whose Invoke is forwarded to the Clojure fn.&lt;/span&gt;
&lt;span class="c1"&gt;;; The arguments are hinted as IJCOBridgeReflected on purpose: javac picks Add(T) from the&lt;/span&gt;
&lt;span class="c1"&gt;;; generic parameter, while Clojure only sees the erased overloads and would otherwise choose&lt;/span&gt;
&lt;span class="c1"&gt;;; the more specific explicit-interface Add(...) that throws UnsupportedOperationException.&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;defn-&lt;/span&gt; &lt;span class="nv"&gt;test-generic-comparison-delegate-sorts-a-list&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;^List_1&lt;/span&gt; &lt;span class="nv"&gt;lst&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;gs/new-generic&lt;/span&gt; &lt;span class="nv"&gt;List_1&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;system.Object&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nv"&gt;calls&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;AtomicInteger.&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;system.Object.&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;system.Object.&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.Add&lt;/span&gt; &lt;span class="nv"&gt;lst&lt;/span&gt; &lt;span class="nv"&gt;^IJCOBridgeReflected&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.Add&lt;/span&gt; &lt;span class="nv"&gt;lst&lt;/span&gt; &lt;span class="nv"&gt;^IJCOBridgeReflected&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;^Comparison_1&lt;/span&gt; &lt;span class="nv"&gt;comparison&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;gs/new-generic&lt;/span&gt; &lt;span class="nv"&gt;Comparison_1&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;system.Object&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                                                   &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"Invoke"&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;_&lt;/span&gt; &lt;span class="nv"&gt;_&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
                                                               &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.incrementAndGet&lt;/span&gt; &lt;span class="nv"&gt;calls&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                                                               &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="c1"&gt;;; Sort is selected by reflection on purpose: javac resolves Sort(Comparison_1&amp;lt;T&amp;gt;) from the&lt;/span&gt;
      &lt;span class="c1"&gt;;; static type, but Clojure compiled the call against Sort(IComparer_1) (ClassCastException).&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;sort-method&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.getMethod&lt;/span&gt; &lt;span class="nv"&gt;List_1&lt;/span&gt; &lt;span class="s2"&gt;"Sort"&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;into-array&lt;/span&gt; &lt;span class="nv"&gt;Class&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;Comparison_1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;try&lt;/span&gt;
          &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.invoke&lt;/span&gt; &lt;span class="nv"&gt;sort-method&lt;/span&gt; &lt;span class="nv"&gt;lst&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;object-array&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;comparison&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
          &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;catch&lt;/span&gt; &lt;span class="nv"&gt;java.lang.reflect.InvocationTargetException&lt;/span&gt; &lt;span class="nv"&gt;e&lt;/span&gt;
            &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;throw&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.getCause&lt;/span&gt; &lt;span class="nv"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;zero?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;.get&lt;/span&gt; &lt;span class="nv"&gt;calls&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;throw&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;AssertionError.&lt;/span&gt; &lt;span class="s2"&gt;"Java comparison never invoked"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is honest about the price: the helper stands in for the{} idiom, and since Clojure only sees the erased overloads, the arguments need a type hint and the Sort call goes through reflection. These are mostly one-time costs: the type hints exist only at compile time, the helper generates and caches one class for each combination of type arguments, and the reflective lookup of Sort can be done once and kept for later calls (the test does it inline because it runs only once). Plain ordinary interop works for everything that is not generic; the generic parts need these few extra steps.&lt;/p&gt;

&lt;h3&gt;
  
  
  So — superfluous?
&lt;/h3&gt;

&lt;p&gt;For the use case ClojureCLR is usually reached for — &lt;em&gt;I’m writing Clojure and I need to call some .NET API&lt;/em&gt; — this is a genuinely strong alternative, and for a lot of people it probably removes the reason to pick ClojureCLR at all. You stay on mainline Clojure, whatever tag it is on. You keep the entire JVM ecosystem — every Maven artifact that exists, with nothing to port. And because JCOBridge hosts a real CLR inside the JVM process rather than replacing it, you can reach into Java libraries and .NET libraries from the same running program, which neither pure ClojureCLR nor pure JVM Clojure can do on its own. JNet is what would make the mirror setup possible, a ClojureCLR program calling JVM libraries, so the two directions are symmetrical: the choice is which runtime you want to be the host.&lt;/p&gt;

&lt;p&gt;Where it doesn’t replace ClojureCLR: if the actual requirement is a native .NET deployment artifact — an assembly that drops into a pure .NET pipeline with no JVM anywhere in the picture — ClojureCLR is still doing a job JCOReflector structurally can’t, because JCOReflector’s whole premise is a JVM process at the center. And the interop itself is more ceremonious on the JCOReflector side: PascalCase generated methods, a helper in place of the {} idiom for generic classes, type hints to pick the right overload, and in the example above a call by reflection, versus ClojureCLR’s (.Method obj) being the real, unmediated thing.&lt;/p&gt;

&lt;p&gt;Different trade-off, not a strictly worse one. But for the person whose actual goal was never “run on .NET” and was always “use some .NET library from Clojure without giving up the JVM I already depend on” — that person may not need to reach for ClojureCLR anymore.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/mario_mastrodicasa_791193/jcoreflector-bringing-net-apis-to-the-jvm-and-now-with-experimental-generics-1l46"&gt;&lt;strong&gt;JCOReflector on Dev&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/masesgroup/JCOReflector" rel="noopener noreferrer"&gt;&lt;strong&gt;JCOReflector on GitHub&lt;/strong&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ClojureCLR&lt;/strong&gt; : &lt;a href="https://github.com/clojure/clojure-clr" rel="noopener noreferrer"&gt;clojure/clojure-clr&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JNet, the mirror project&lt;/strong&gt; : &lt;a href="https://github.com/masesgroup/JNet" rel="noopener noreferrer"&gt;masesgroup/JNet&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The bridge underneath&lt;/strong&gt; : &lt;a href="https://www.jcobridge.com" rel="noopener noreferrer"&gt;jcobridge.com&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>jvm</category>
      <category>clojure</category>
      <category>clojureclr</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>JCOReflector: bringing .NET APIs to the JVM — and now with generics</title>
      <dc:creator>Mario Mastrodicasa</dc:creator>
      <pubDate>Tue, 06 Oct 2026 12:15:53 +0000</pubDate>
      <link>https://dev.to/mario_mastrodicasa/jcoreflector-bringing-net-apis-to-the-jvm-and-now-with-experimental-generics-1l46</link>
      <guid>https://dev.to/mario_mastrodicasa/jcoreflector-bringing-net-apis-to-the-jvm-and-now-with-experimental-generics-1l46</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9vixeruruumbnvht1nfc.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9vixeruruumbnvht1nfc.jpeg" width="800" height="1000"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by Michiel Leunens on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you’ve read about &lt;a href="https://dev.to/mario_mastrodicasa_791193/java-apis-written-in-c-jvm-and-net-side-by-side-31bk"&gt;JNet&lt;/a&gt;, you already know the shape of the problem: running two runtimes side by side, in one process, without marshalling everything through JSON or a TCP socket. &lt;a href="https://github.com/masesgroup/JNet" rel="noopener noreferrer"&gt;JNet&lt;/a&gt; solves it in one direction — a real JVM inside a .NET process, with the Java API surface exposed as C#. JCOReflector solves it in the other direction: a real CLR inside a JVM process, with the .NET API surface exposed as Java (and, by extension, Scala, Kotlin, and Clojure, since they all compile to the same bytecode).&lt;/p&gt;

&lt;p&gt;Both tools sit on top of &lt;a href="https://www.jcobridge.com" rel="noopener noreferrer"&gt;JCOBridge&lt;/a&gt;, the library that actually owns the inter-runtime boundary. JCOReflector’s job is narrower and more mechanical: point it at a .NET assembly, and it generates a complete, compilable Java class for every public type it finds — constructors, methods, properties, events, exceptions, the works — so that calling into .NET from Java looks and feels like calling into any other Java library.&lt;/p&gt;

&lt;p&gt;This article covers what JCOReflector generates today, and — the reason this is worth writing now — the support for .NET generics that just landed, including where it genuinely can't follow .NET's lead and why.&lt;/p&gt;
&lt;h3&gt;
  
  
  What a generated class looks like
&lt;/h3&gt;

&lt;p&gt;Point the CLI at an assembly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MASES.JCOReflectorCLI -JobType Reflect -JobFile reflect.job
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;using the configuration file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;ReflectorEventArgs&lt;/span&gt; &lt;span class="na"&gt;xmlns:xsd&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"http://www.w3.org/2001/XMLSchema"&lt;/span&gt; &lt;span class="na"&gt;xmlns:xsi&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"http://www.w3.org/2001/XMLSchema-instance"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;LogLevel&amp;gt;&lt;/span&gt;Error&lt;span class="nt"&gt;&amp;lt;/LogLevel&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;AssemblyNames&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;string&amp;gt;&lt;/span&gt;PresentationFramework, Version=8.0.0.0&lt;span class="nt"&gt;&amp;lt;/string&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/AssemblyNames&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;SourceFolder&amp;gt;&lt;/span&gt;src/jvm&lt;span class="nt"&gt;&amp;lt;/SourceFolder&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;SplitFolderByAssembly&amp;gt;&lt;/span&gt;true&lt;span class="nt"&gt;&amp;lt;/SplitFolderByAssembly&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ForceRebuild&amp;gt;&lt;/span&gt;true&lt;span class="nt"&gt;&amp;lt;/ForceRebuild&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;UseParallelBuild&amp;gt;&lt;/span&gt;true&lt;span class="nt"&gt;&amp;lt;/UseParallelBuild&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;CreateExceptionThrownClause&amp;gt;&lt;/span&gt;true&lt;span class="nt"&gt;&amp;lt;/CreateExceptionThrownClause&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ExceptionThrownClauseDepth&amp;gt;&lt;/span&gt;10&lt;span class="nt"&gt;&amp;lt;/ExceptionThrownClauseDepth&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;EnableAbstract&amp;gt;&lt;/span&gt;true&lt;span class="nt"&gt;&amp;lt;/EnableAbstract&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;EnableArray&amp;gt;&lt;/span&gt;true&lt;span class="nt"&gt;&amp;lt;/EnableArray&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;EnableDuplicateMethodNativeArrayWithJCRefOut&amp;gt;&lt;/span&gt;true&lt;span class="nt"&gt;&amp;lt;/EnableDuplicateMethodNativeArrayWithJCRefOut&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;EnableInheritance&amp;gt;&lt;/span&gt;true&lt;span class="nt"&gt;&amp;lt;/EnableInheritance&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;EnableInterfaceInheritance&amp;gt;&lt;/span&gt;true&lt;span class="nt"&gt;&amp;lt;/EnableInterfaceInheritance&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;EnableRefOutParameters&amp;gt;&lt;/span&gt;true&lt;span class="nt"&gt;&amp;lt;/EnableRefOutParameters&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;EnableGenerics&amp;gt;&lt;/span&gt;true&lt;span class="nt"&gt;&amp;lt;/EnableGenerics&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;DryRun&amp;gt;&lt;/span&gt;false&lt;span class="nt"&gt;&amp;lt;/DryRun&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ReflectorEventArgs&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What comes out isn’t a thin proxy — it’s a real Java class with a real relationship to the .NET type behind it. Three conventions carry through every single generated file:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Properties become explicit&lt;/strong&gt; &lt;strong&gt;getX()/&lt;/strong&gt;&lt;strong&gt;setX() pairs.&lt;/strong&gt; .NET property syntax has no Java equivalent, so there's no attempt to fake it — list.Count becomes list.getCount().&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Events become explicit&lt;/strong&gt;  &lt;strong&gt;addX/&lt;/strong&gt;** removeX methods**, not +=/-=. A System.Timers.Timer in Java looks like:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Timer&lt;/span&gt; &lt;span class="n"&gt;timer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Timer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;TimerElapsed&lt;/span&gt; &lt;span class="n"&gt;elapsed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TimerElapsed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addElapsed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;elapsed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setEnabled&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="n"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeElapsed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;elapsed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;[Flags] enums get&lt;/strong&gt; &lt;strong&gt;add(...)/&lt;/strong&gt;&lt;strong&gt;remove(...) methods&lt;/strong&gt; standing in for |=/&amp;amp;= ~, since Java doesn't allow overloading bitwise operators on an enum type.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Underneath, every generated class implements a single marker interface, IJCOBridgeReflected, and carries the metadata needed to round-trip itself across the bridge: a className field holding the fully-qualified CLR type name, and a getJCOInstance()/setJCOInstance() pair that exposes the underlying native handle. That marker interface turns out to matter a lot once generics enter the picture.&lt;/p&gt;

&lt;h3&gt;
  
  
  The generics problem
&lt;/h3&gt;

&lt;p&gt;Until recently, JCOReflector simply discarded every generic .NET type and member during reflection. A generic class, interface, delegate, or method was invisible to the generator — which meant List, Dictionary, Task, and most of LINQ never showed up in the generated output at all. For a tool whose whole purpose is exposing the .NET API surface, that's a conspicuous gap: most of modern .NET is generic.&lt;/p&gt;

&lt;p&gt;The reason it was skipped isn’t laziness — it’s a real mismatch between how the two platforms implement generics. .NET generics are &lt;em&gt;reified&lt;/em&gt;: List and List are distinct types at runtime, each with its own compiled code and its own static state. Java generics are implemented via &lt;em&gt;type erasure&lt;/em&gt;: List and List share one compiled class, and every trace of the type argument is gone by the time the bytecode runs. Closing that gap means working around erasure everywhere it would otherwise be a compile error — and, in a few well-defined cases, admitting that a particular .NET generic API simply has no honest Java representation.&lt;/p&gt;

&lt;h3&gt;
  
  
  How it works: the “super type token” trick
&lt;/h3&gt;

&lt;p&gt;A reflected generic .NET type becomes a parameterized Java class, with every type parameter bounded by IJCOBridgeReflected:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;List_1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;IJCOBridgeReflected&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;NetObject&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(the _1 suffix is an arity marker — Dictionary_2, Lazy_1 vs Lazy_2 — needed because .NET allows same-named types with different arity, which Java's package namespace doesn't distinguish on its own.)&lt;/p&gt;

&lt;p&gt;Constructing one of these requires a trailing {}:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="nc"&gt;List_1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;NetObject&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;List_1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;NetObject&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NetObject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That trailing {} isn't decoration — it's the whole mechanism. It's the same "super type token" idiom used by Gson's TypeToken and Guava: erasure throws away a class's own generic type argument, but the JVM &lt;em&gt;does&lt;/em&gt; keep that information on the supertype of an anonymous subclass. new List_1(){}.getClass().getGenericSuperclass() hands back a ParameterizedType carrying Foo.class, intact. Construct without the {} and you get a clear, immediate IllegalArgumentException rather than a confusing failure three calls later.&lt;/p&gt;

&lt;p&gt;That recovered Class&amp;lt;?&amp;gt; is cached on the instance and reused by a small reflective helper, instantiateGenericArgument, anywhere the generated code needs to build a new instance of the type parameter — because new T(...) is flatly illegal Java (erasure removes T at runtime; the compiler has nothing to new). An array of T has the same problem and the same fix, via java.lang.reflect.Array.newInstance instead of new T[].&lt;/p&gt;

&lt;p&gt;Generic &lt;strong&gt;delegates&lt;/strong&gt; needed a variant of the same trick. Comparison, Func, and friends extend JCDelegate rather than NetObject, so they can't reuse NetObject's machinery directly — a small shared helper, NetGenericHelper, plays the same role, resolving the closed CLR delegate type lazily the first time it's needed instead of requiring the caller to build a type name by hand. From the call site, it looks exactly like everything else:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="nc"&gt;List_1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;list&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;List_1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nc"&gt;Comparison_1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;comparison&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Comparison_1&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Object&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;@Override&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nc"&gt;Invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Object&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// real comparison logic goes here&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;comparison&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same new X() {} idiom whether X is a collection or a delegate; the type argument recovery and the CLR-side type resolution both happen underneath, out of the caller's way.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where it has to say no
&lt;/h3&gt;

&lt;p&gt;Not everything maps. Four categories are excluded on purpose, and it’s worth being explicit about why, rather than leaving them as silent gaps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;ref struct types&lt;/strong&gt;  — Span, ReadOnlySpan. These wrap a native pointer or stack reference that can't be boxed and can't cross the bridge as an object. There's no Java representation for this, period; the type and anything that uses it as a parameter or return type is skipped entirely.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;“Generic math” interfaces&lt;/strong&gt;  — INumber and the whole C# 11 family built on &lt;em&gt;static abstract interface members&lt;/em&gt;. Java interfaces can't declare a static abstract member at all — there's no partial solution here, the feature just doesn't exist on the JVM side.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A type parameter that belongs to a method, not a class.&lt;/strong&gt; List's own T can be recovered because an instance exists to hang the anonymous-subclass trick on. Array.Empty() has no instance — there's no moment where a Class is ever available — so it's skipped rather than emitting code that references an unresolvable type.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A class-level type parameter referenced from a&lt;/strong&gt;  &lt;strong&gt;static member.&lt;/strong&gt;  .NET gives every closed generic instantiation its own independent static state; Java has exactly one shared class per raw type regardless of how many parameterizations exist. A static method genuinely cannot see the class's own T in Java, so these are skipped too.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A fifth case doesn’t skip anything — it renames. Some .NET members only collide because erasure throws away the information that made them distinct: IEqualityComparer.Equals(T, T) would otherwise erase to the exact same signature as the base Equals(IJCOBridgeReflected, IJCOBridgeReflected) every generated class already has, so it's emitted as EqualsGeneric(...) instead of being lost. KeyedCollection.Remove(TKey) becomes RemoveByKey(...) for the same reason, against the inherited Collection.Remove(TItem).&lt;/p&gt;

&lt;p&gt;And one case is a hard language rule with no workaround at all: &lt;strong&gt;a generic class can never extend&lt;/strong&gt;  &lt;strong&gt;java.lang.Throwable&lt;/strong&gt; (JLS §8.1.2). A .NET generic exception like &lt;a href="https://learn.microsoft.com/dotnet/api/system.servicemodel.faultexception-1" rel="noopener noreferrer"&gt;FaultException&lt;/a&gt; is therefore always generated as a plain, non-generic class, with TDetail exposed everywhere as its bound, IJCOBridgeReflected, rather than as a real type variable. It's the one spot where the generic parameter is erased to its bound in the &lt;em&gt;public API&lt;/em&gt;, not just internally — by necessity, not by choice.&lt;/p&gt;

&lt;h3&gt;
  
  
  Current status
&lt;/h3&gt;

&lt;p&gt;Generics are controlled by a single engine switch (&lt;code&gt;EnableGenerics&lt;/code&gt;), off by default in the reflector tool and enabled in the CI that produces the published JARs. The mechanisms above are implemented and test-covered — collections, generic delegates as synchronous callbacks, the rename strategy for erasure collisions, the exception fallback — across every target JVM language the project supports, not just Java.&lt;/p&gt;

&lt;p&gt;Two things are explicitly still open, and worth naming rather than glossing over: a handful of .NET interfaces remain excluded pending further work — IAlternateEqualityComparer (.NET 9+, a two-different-type-parameter variant of the Equals collision the rename logic doesn't yet detect) and INameScopeDictionary (whose generated wrapper class currently only collects members declared directly on the interface, not the full inherited interface closure).&lt;/p&gt;

&lt;h3&gt;
  
  
  Where to go from here
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Full write-up of what’s supported and what isn’t&lt;/strong&gt; : &lt;a href="https://jcoreflector.masesgroup.com/articles/generics.html" rel="noopener noreferrer"&gt;generics&lt;/a&gt; in the project documentation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JCOReflector on GitHub&lt;/strong&gt; : &lt;a href="https://github.com/masesgroup/JCOReflector" rel="noopener noreferrer"&gt;masesgroup/JCOReflector&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The other direction (Java APIs in .NET)&lt;/strong&gt;: &lt;a href="https://github.com/masesgroup/JNet" rel="noopener noreferrer"&gt;JNet&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The bridge underneath both&lt;/strong&gt; : &lt;a href="https://www.jcobridge.com" rel="noopener noreferrer"&gt;jcobridge.com&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>scala</category>
      <category>dotnet</category>
      <category>kotlin</category>
      <category>java</category>
    </item>
    <item>
      <title>KEFCore performance: query optimization and persistent storage</title>
      <dc:creator>Mario Mastrodicasa</dc:creator>
      <pubDate>Mon, 17 Aug 2026 07:20:36 +0000</pubDate>
      <link>https://dev.to/mario_mastrodicasa/kefcore-performance-query-optimization-and-persistent-storage-377b</link>
      <guid>https://dev.to/mario_mastrodicasa/kefcore-performance-query-optimization-and-persistent-storage-377b</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2k462lwfrr84avtbyjvu.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2k462lwfrr84avtbyjvu.jpeg" alt="Photo by Nicolas Hoizey on Unsplash" width="800" height="1200"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by Nicolas Hoizey on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Part of the KEFCore series. See also:&lt;/em&gt; &lt;a href="https://dev.to/mario_mastrodicasa_791193/kefcore-apache-kafka-provider-for-entity-framework-core-1mbi"&gt;&lt;em&gt;introduction&lt;/em&gt;&lt;/a&gt; &lt;em&gt;·&lt;/em&gt; &lt;a href="https://dev.to/mario_mastrodicasa_791193/entity-framework-core-provider-for-apache-kafka-how-it-works-and-use-cases-1j66"&gt;&lt;em&gt;how it works&lt;/em&gt;&lt;/a&gt; &lt;em&gt;·&lt;/em&gt; &lt;a href="https://dev.to/mario_mastrodicasa_791193/entity-framework-core-provider-for-apache-kafka-performance-3m36"&gt;&lt;em&gt;original performance article&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The original performance article compared KNetCompactedReplicator against Kafka Streams as two backend options. That comparison no longer applies — KNetCompactedReplicator has been deprecated and removed. KEFCore today is built exclusively on Kafka Streams, and the performance story is about how well you use that engine.&lt;/p&gt;

&lt;p&gt;This article covers the query-level optimizations introduced since then, persistent storage behavior, RocksDB tuning, and the configuration knobs that matter most in production.&lt;/p&gt;
&lt;h3&gt;
  
  
  How KEFCore queries work
&lt;/h3&gt;

&lt;p&gt;Every DbContext instance backed by KEFCore maintains a local Kafka Streams state store — either in-memory or RocksDB. LINQ queries are translated by the EF Core query pipeline and then executed against this local store. No network round-trip to the broker happens at query time; the store is always local and always up to date via the Streams topology.&lt;/p&gt;

&lt;p&gt;The default query path is a full store scan. The optimizations described below short-circuit that scan by delegating directly to the state store API when the query shape allows it.&lt;/p&gt;
&lt;h3&gt;
  
  
  Store-level query optimizations
&lt;/h3&gt;

&lt;p&gt;Four optimizations are available, all context-scoped (can differ between DbContext instances on the same cluster) and enabled by default:&lt;/p&gt;
&lt;h3&gt;
  
  
  Single key lookup — UseStoreSingleKeyLookup (default: true)
&lt;/h3&gt;

&lt;p&gt;For primary key equality predicates, KEFCore calls store.get(key) directly instead of scanning:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Full scan without optimization → O(n)&lt;/span&gt;
&lt;span class="c1"&gt;// Direct store.get(key) with optimization → O(log n) on RocksDB, O(1) on in-memory&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;blog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Blogs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Single&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;blog&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Blogs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Key range scan — UseStoreKeyRange (default: true)
&lt;/h3&gt;

&lt;p&gt;For primary key range predicates, KEFCore calls store.range(from, to):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;blogs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Blogs&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Reverse iteration — UseStoreReverse (default: true)
&lt;/h3&gt;

&lt;p&gt;For Last()/LastOrDefault() without a range, KEFCore calls store.reverseAll():&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;latest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Blogs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OrderByDescending&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;First&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Reverse range scan — UseStoreReverseKeyRange (default: true)
&lt;/h3&gt;

&lt;p&gt;For Last()/LastOrDefault() with a primary key range:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;latestInRange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Blogs&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Where&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OrderByDescending&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlogId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;First&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Per-entity overrides
&lt;/h3&gt;

&lt;p&gt;All four optimizations can be overridden per entity type without affecting the global configuration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Via attribute&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;KEFCoreStoreLookupAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;useSingleKeyLookup&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;useKeyRange&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;useReverse&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;useReverseKeyRange&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Blog&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Via fluent API&lt;/span&gt;
&lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;OnModelCreating&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ModelBuilder&lt;/span&gt; &lt;span class="n"&gt;modelBuilder&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;modelBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Entity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Blog&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;HasKEFCoreStoreLookup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;useReverse&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;useReverseKeyRange&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Disable what you do not need to reduce state store API surface and avoid unexpected behavior on non-standard key types.&lt;/p&gt;

&lt;h3&gt;
  
  
  In-memory vs persistent storage
&lt;/h3&gt;

&lt;p&gt;UsePersistentStorage (singleton, default: false) controls the Streams state store backend:&lt;/p&gt;

&lt;p&gt;In-memory RocksDB Startup Instant — empty store Fast — resumes from checkpoint Memory All data in RAM Spills to disk Restart behavior Full replay from topic Incremental — only new records Best for Development, short-lived processes Production, large datasets&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BloggingContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;BootstrapServers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"MY-KAFKA-BROKER:9092"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;ApplicationId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"MyApp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;UsePersistentStorage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With persistent storage, the RocksDB state directory is identified by ApplicationId and the storage ID derived from the entity topic name and cluster ID. Changing any of these between restarts will produce a new storage ID and trigger a full rebuild.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;To force a clean rebuild even with persistent storage — for example after a schema change — call&lt;/em&gt; &lt;em&gt;context.Database.EnsureDeleted() before&lt;/em&gt; &lt;em&gt;EnsureCreated(). This deletes the topics and the local state directory.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  RocksDB lifecycle configuration
&lt;/h3&gt;

&lt;p&gt;When UsePersistentStorage = true, per-store RocksDB options can be tuned via KEFCoreRocksDbLifecycleAttribute or fluent API. Two models are supported:&lt;/p&gt;

&lt;h3&gt;
  
  
  Handler type
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nc"&gt;Org&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Apache&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Kafka&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Streams&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;State&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyRocksDbHandler&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;IRocksDbLifecycleHandler&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;OnSetConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Org&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rocksdb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Options&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                            &lt;span class="nc"&gt;IKNetConfigurationFromMap&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                            &lt;span class="nc"&gt;IDictionary&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;object&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;blockCache&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Org&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rocksdb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;LRUCache&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;256&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1024L&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SetBlockBasedTableFactory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Org&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rocksdb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlockBasedTableConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SetBlockCache&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blockCache&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"blockCache"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;blockCache&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// keep alive - released in OnClose&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;OnClose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Org&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rocksdb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Options&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;IDictionary&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;object&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TryGetValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"blockCache"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;bc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bc&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;IDisposable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Dispose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;KEFCoreRocksDbLifecycleAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MyRocksDbHandler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"SensorReading"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SensorReading&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Inline callbacks
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;OnModelCreating&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ModelBuilder&lt;/span&gt; &lt;span class="n"&gt;modelBuilder&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;modelBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Entity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;SensorReading&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;HasKEFCoreRocksDbLifecycle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;onSetConfig&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;blockCache&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Org&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rocksdb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;LRUCache&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;256&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1024L&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SetBlockBasedTableFactory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Org&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Rocksdb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BlockBasedTableConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SetBlockCache&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blockCache&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"blockCache"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;blockCache&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;onClose&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TryGetValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"blockCache"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;out&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;bc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bc&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;IDisposable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Dispose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The data dictionary is the per-store lifetime container. Any managed .NET object referenced by a native RocksDB component after OnSetConfig returns must be stored in data to prevent GC collection before OnClose is called.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;UsePersistentStorage = true is required for RocksDB lifecycle callbacks to be invoked. With in-memory storage the callbacks are never called.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Producer configuration per entity
&lt;/h3&gt;

&lt;p&gt;ProducerConfig is a cluster-level first-wins option. Individual entity types can override producer settings to achieve mixed throughput and reliability profiles on the same cluster:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// High-throughput entity: batching, compression, relaxed acks&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;KEFCoreProducerAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;acks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lingerMs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;batchSize&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;65536&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                          &lt;span class="n"&gt;compressionType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"lz4"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"MetricSample"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MetricSample&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Audit entity: full durability&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;KEFCoreProducerAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;acks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"all"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;retries&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"AuditEvent"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AuditEvent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or via fluent API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;modelBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Entity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MetricSample&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;HasKEFCoreProducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithAcks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithLingerMs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithCompressionType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"lz4"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Synchronization timeout
&lt;/h3&gt;

&lt;p&gt;DefaultSynchronizationTimeout (context-scoped, default: Timeout.Infinite) controls how long KEFCore waits after SaveChanges for the Streams state store to acknowledge the new offsets:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Wait up to 5 seconds after SaveChanges&lt;/span&gt;
&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DefaultSynchronizationTimeout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Disable synchronization - for write-only producers&lt;/span&gt;
&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DefaultSynchronizationTimeout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For high-throughput write scenarios where you do not need to immediately read back what you wrote, set DefaultSynchronizationTimeout = 0:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;optionsBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UseKEFCore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;opt&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithBootstrapServers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"KAFKA-SERVER:9092"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithDefaultSynchronizationTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Synchronization is only available when event management is enabled for the entity. If&lt;/em&gt; &lt;em&gt;[KEFCoreIgnoreEventsAttribute] is applied or&lt;/em&gt; &lt;em&gt;HasKEFCoreManageEvents(false) is set, the synchronization wait is skipped regardless of&lt;/em&gt; &lt;em&gt;DefaultSynchronizationTimeout.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Event management per entity
&lt;/h3&gt;

&lt;p&gt;By default KEFCore activates TimestampExtractor for all entity types, enabling real-time local state updates and post-SaveChanges synchronization. For entities that are never written by the current process — reference data, lookup tables — disable event management to reduce CPU overhead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;KEFCoreIgnoreEventsAttribute&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"CountryCodes"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CountryCode&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Or globally, for pure consumers&lt;/span&gt;
&lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nc"&gt;OnModelCreating&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ModelBuilder&lt;/span&gt; &lt;span class="n"&gt;modelBuilder&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;modelBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UseKEFCoreManageEvents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;base&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OnModelCreating&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;modelBuilder&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Data transfer: byte[] vs ByteBuffer
&lt;/h3&gt;

&lt;p&gt;KEFCore supports two data transfer modes between .NET and the JVM for serialization:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;byte[]&lt;/strong&gt; (default): standard managed array, copied across the JVM boundary on each operation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ByteBuffer&lt;/strong&gt; : direct JVM buffer, avoids array copying — lower memory pressure and better throughput under load.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;optionsBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UseKEFCore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;opt&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithBootstrapServers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"KAFKA-SERVER:9092"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithKeyByteBufferDataTransfer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// default: false&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithValueContainerByteBufferDataTransfer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// default: false&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are singleton options — they affect the Streams topology and must be consistent across all contexts on the same cluster. Enable ByteBuffer when throughput is a priority and your serializer supports it. The default JSON serializer supports both modes; Avro and Protobuf serializers also support ByteBuffer via their Buffered variants.&lt;/p&gt;

&lt;h3&gt;
  
  
  JCOBridge HPA edition
&lt;/h3&gt;

&lt;p&gt;Several intermittent errors under sustained load — including TimestampExtractor callback failures — share the same root cause: non-deterministic GC interactions at the JVM↔CLR boundary under sustained call pressure.&lt;/p&gt;

&lt;p&gt;Workarounds at the application level (disabling event management, REPLACE_THREAD recovery) reduce frequency or recover gracefully but do not eliminate the root cause. The &lt;strong&gt;JCOBridge HPA (High Performance Application) edition&lt;/strong&gt; addresses these failures at the interop layer. If your application:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;runs with event management enabled on high-throughput entities&lt;/li&gt;
&lt;li&gt;uses ByteBuffer data transfer&lt;/li&gt;
&lt;li&gt;experiences intermittent stream thread failures under load&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;then the HPA edition is the recommended path. See &lt;a href="https://www.jcobridge.com" rel="noopener noreferrer"&gt;jcobridge.com&lt;/a&gt; for licensing and availability.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where to go from here
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Performance tips&lt;/strong&gt; : &lt;a href="https://kefcore.masesgroup.com/articles/performancetips.html" rel="noopener noreferrer"&gt;kefcore.masesgroup.com/articles/performancetips.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Options reference&lt;/strong&gt; : &lt;a href="https://kefcore.masesgroup.com/articles/options.html" rel="noopener noreferrer"&gt;kefcore.masesgroup.com/articles/options.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Conventions&lt;/strong&gt; : &lt;a href="https://kefcore.masesgroup.com/articles/conventions.html" rel="noopener noreferrer"&gt;kefcore.masesgroup.com/articles/conventions.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GitHub&lt;/strong&gt; : &lt;a href="https://github.com/masesgroup/KEFCore" rel="noopener noreferrer"&gt;masesgroup/KEFCore&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;KAFKA is a registered trademark of The Apache Software Foundation. MASES Group has no affiliation with and is not endorsed by The Apache Software Foundation.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>apachekafka</category>
      <category>rocksdb</category>
      <category>queryoptimization</category>
      <category>performance</category>
    </item>
    <item>
      <title>KEFCore and broker security: TLS and SASL with managed Kafka clusters</title>
      <dc:creator>Mario Mastrodicasa</dc:creator>
      <pubDate>Mon, 10 Aug 2026 06:35:03 +0000</pubDate>
      <link>https://dev.to/mario_mastrodicasa/kefcore-and-broker-security-tls-and-sasl-with-managed-kafka-clusters-53kk</link>
      <guid>https://dev.to/mario_mastrodicasa/kefcore-and-broker-security-tls-and-sasl-with-managed-kafka-clusters-53kk</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5mib4p3fgfc0i3gedw8m.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5mib4p3fgfc0i3gedw8m.jpeg" width="800" height="534"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by FlyD on Unsplash&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Part of the KEFCore series. See also:&lt;/em&gt; &lt;a href="https://dev.to/mario_mastrodicasa_791193/kefcore-apache-kafka-provider-for-entity-framework-core-1mbi"&gt;&lt;em&gt;introduction&lt;/em&gt;&lt;/a&gt; &lt;em&gt;·&lt;/em&gt; &lt;a href="https://dev.to/mario_mastrodicasa_791193/entity-framework-core-provider-for-apache-kafka-how-it-works-and-use-cases-1j66"&gt;&lt;em&gt;how it works&lt;/em&gt;&lt;/a&gt; &lt;em&gt;·&lt;/em&gt; &lt;a href="https://dev.to/mario_mastrodicasa_791193/entity-framework-core-provider-for-apache-kafka-performance-3m36"&gt;&lt;em&gt;performance&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Production Kafka clusters — whether self-hosted or managed (Amazon MSK, Confluent Cloud, Aiven, Redpanda Cloud) — require encrypted and authenticated connections. KEFCore now exposes SecurityProtocol, SslConfigs, and SaslConfigs as first-class configuration options, making it straightforward to connect to any secured broker without touching the underlying KNet or JVM configuration directly.&lt;/p&gt;

&lt;p&gt;This article covers how to configure KEFCore for the most common security scenarios.&lt;/p&gt;
&lt;h3&gt;
  
  
  The four security protocols
&lt;/h3&gt;

&lt;p&gt;SecurityProtocol controls how KEFCore connects to the broker:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Value Encryption Authentication
---------------------------------------------
PLAINTEXT None None
SSL TLS None
SASL_PLAINTEXT None SASL
SASL_SSL TLS SASL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For any production cluster, use SSL or SASL_SSL. The combination most commonly required by managed brokers (MSK IAM, Confluent Cloud, Aiven, Redpanda Cloud) is SASL_SSL.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;SecurityProtocol,&lt;/em&gt; &lt;em&gt;SslConfigs, and&lt;/em&gt; &lt;em&gt;SaslConfigs are&lt;/em&gt; &lt;strong&gt;&lt;em&gt;first-wins singleton options&lt;/em&gt;&lt;/strong&gt; &lt;em&gt; — the values set by the first&lt;/em&gt; &lt;em&gt;DbContext to initialize the cluster are used for all subsequent contexts on the same cluster. Ensure all&lt;/em&gt; &lt;em&gt;DbContext instances that share the same&lt;/em&gt; &lt;em&gt;BootstrapServers use the same security configuration.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  TLS only — SSL
&lt;/h3&gt;

&lt;p&gt;Use this when the broker requires an encrypted connection but not SASL authentication (e.g. self-hosted Kafka with a custom CA, some on-premises Confluent Platform deployments):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;optionsBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UseKEFCore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;opt&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithBootstrapServers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"KAFKA-SERVER:9093"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithApplicationId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"MyApp"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSecurityProtocol&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SecurityProtocol&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;SSL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSslConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SslConfigsBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSslTruststoreLocation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/path/to/truststore.jks"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSslTruststorePassword&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"truststore-password"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;// optional: mutual TLS (client certificate)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSslKeystoreLocation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/path/to/keystore.jks"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSslKeystoreLocation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"keystore-password"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or directly on KEFCoreDbContext:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BloggingContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;BootstrapServers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"KAFKA-SERVER:9093"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;ApplicationId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"MyApp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;SecurityProtocol&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;SecurityProtocol&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;SSL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;SslConfigs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SslConfigsBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSslTruststoreLocation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/path/to/truststore.jks"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSslTruststorePassword&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"truststore-password"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  TLS + SASL/PLAIN — SASL_SSL
&lt;/h3&gt;

&lt;p&gt;The most common configuration for managed brokers. SASL/PLAIN sends credentials as username and password, encrypted by TLS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;optionsBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UseKEFCore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;opt&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithBootstrapServers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"KAFKA-SERVER:9093"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithApplicationId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"MyApp"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSecurityProtocol&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SecurityProtocol&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;SASL_SSL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSslConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SslConfigsBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSslTruststoreLocation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/path/to/truststore.jks"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSslTruststorePassword&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"truststore-password"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SaslConfigsBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslMechanism&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"PLAIN"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslJaasConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s2"&gt;"org.apache.kafka.common.security.plain.PlainLoginModule required "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
            &lt;span class="s2"&gt;"username=\"myuser\" password=\"mypassword\";"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  TLS + SASL/SCRAM — SASL_SSL
&lt;/h3&gt;

&lt;p&gt;SCRAM (Salted Challenge Response Authentication Mechanism) is used by self-hosted Kafka clusters that require stronger authentication than PLAIN. Replace the mechanism and login module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SaslConfigsBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslMechanism&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"SCRAM-SHA-256"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// or "SCRAM-SHA-512"&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslJaasConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="s2"&gt;"org.apache.kafka.common.security.scram.ScramLoginModule required "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
        &lt;span class="s2"&gt;"username=\"myuser\" password=\"mypassword\";"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Kerberos (GSSAPI)
&lt;/h3&gt;

&lt;p&gt;The default SASL mechanism when SaslConfigs is set without an explicit WithSaslMechanism() call is GSSAPI (Kerberos). Configure the service name and kinit command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SaslConfigsBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslKerberosServiceName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"kafka"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslKerberosKinitCmd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/usr/bin/kinit"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  OAuth / SASL/OAUTHBEARER
&lt;/h3&gt;

&lt;p&gt;For brokers integrated with an identity provider (e.g. Confluent Cloud with OAuth, MSK with IAM via OAUTHBEARER):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SaslConfigsBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslMechanism&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"OAUTHBEARER"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslOauthBearerTokenEndpointUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"https://your-idp/oauth/token"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslOauthBearerClientCredentialsClientId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"client-id"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslOauthBearerClientCredentialsClientSecret&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"client-secret"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Provider-specific examples
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Amazon MSK (IAM authentication)
&lt;/h3&gt;

&lt;p&gt;MSK with IAM uses SASL_SSL with OAUTHBEARER and the AWS MSK IAM login module. The truststore is the standard Java CA bundle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;optionsBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UseKEFCore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;opt&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithBootstrapServers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"your-msk-endpoint:9098"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithApplicationId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"MyApp"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSecurityProtocol&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SecurityProtocol&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;SASL_SSL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SaslConfigsBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslMechanism&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"AWS_MSK_IAM"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslJaasConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s2"&gt;"software.amazon.msk.auth.iam.IAMLoginModule required;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Confluent Cloud
&lt;/h3&gt;

&lt;p&gt;Confluent Cloud uses SASL_SSL with PLAIN and API key/secret as credentials:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;optionsBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UseKEFCore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;opt&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithBootstrapServers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"pkc-xxxxx.region.confluent.cloud:9092"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithApplicationId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"MyApp"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSecurityProtocol&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SecurityProtocol&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;SASL_SSL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SaslConfigsBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslMechanism&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"PLAIN"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslJaasConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s2"&gt;"org.apache.kafka.common.security.plain.PlainLoginModule required "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
            &lt;span class="s2"&gt;"username=\"API_KEY\" password=\"API_SECRET\";"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No SslConfigs needed — Confluent Cloud uses a publicly trusted CA.&lt;/p&gt;

&lt;h3&gt;
  
  
  Aiven for Apache Kafka™
&lt;/h3&gt;

&lt;p&gt;Aiven uses SSL with mutual TLS (client certificate required):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;optionsBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UseKEFCore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;opt&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithBootstrapServers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"your-service.aivencloud.com:PORT"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithApplicationId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"MyApp"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSecurityProtocol&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SecurityProtocol&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;SSL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSslConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SslConfigsBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSslTruststoreLocation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/path/to/aiven-truststore.jks"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSslTruststorePassword&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"truststore-password"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSslKeystoreLocation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/path/to/aiven-keystore.jks"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSslKeystoreLocation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"keystore-password"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Redpanda Cloud
&lt;/h3&gt;

&lt;p&gt;Redpanda Cloud uses the same SASL_SSL + SCRAM-SHA-256 pattern:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;optionsBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UseKEFCore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;opt&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithBootstrapServers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"your-cluster.redpanda.com:9092"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithApplicationId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"MyApp"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSecurityProtocol&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SecurityProtocol&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;SASL_SSL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SaslConfigsBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslMechanism&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"SCRAM-SHA-256"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslJaasConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s2"&gt;"org.apache.kafka.common.security.scram.ScramLoginModule required "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
            &lt;span class="s2"&gt;"username=\"myuser\" password=\"mypassword\";"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Credentials from environment or secret manager
&lt;/h3&gt;

&lt;p&gt;Never hardcode credentials in code. Read them at startup from environment variables or a secret manager:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;apiKey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Environment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetEnvironmentVariable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"KAFKA_API_KEY"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;apiSecret&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Environment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetEnvironmentVariable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"KAFKA_API_SECRET"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;optionsBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UseKEFCore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;opt&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;opt&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithBootstrapServers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Environment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetEnvironmentVariable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"KAFKA_BOOTSTRAP"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithApplicationId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"MyApp"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSecurityProtocol&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SecurityProtocol&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;SASL_SSL&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SaslConfigsBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslMechanism&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"PLAIN"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithSaslJaasConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Password&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="s2"&gt;"org.apache.kafka.common.security.plain.PlainLoginModule required "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
            $&lt;span class="s2"&gt;"username=\"{apiKey}\" password=\"{apiSecret}\";"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For ASP.NET Core, inject configuration via IConfiguration and bind from appsettings.json or Azure Key Vault / AWS Secrets Manager.&lt;/p&gt;

&lt;h3&gt;
  
  
  SSL configuration reference
&lt;/h3&gt;

&lt;p&gt;SslConfigsBuilder exposes the full set of Kafka SSL properties. The most commonly needed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Property Method Notes
----------------------------------------------------------------------------------------------
Truststore path WithSslTruststoreLocation JKS file path
Truststore password WithSslTruststorePassword Password type
Keystore path WithSslKeystoreLocation For mutual TLS
Keystore password WithSslKeystoreLocation(Password) For mutual TLS
TLS protocol WithSslProtocol Default: TLSv1.3
Endpoint identification WithSslEndpointIdentificationAlgorithm "https" (default)
                                                                                  or "" to disable
                                                                                  hostname verification
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Disabling hostname verification (&lt;/em&gt;&lt;em&gt;WithSslEndpointIdentificationAlgorithm("")) should only be used in development. In production it removes a critical security check.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Where to go from here
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Options reference&lt;/strong&gt; : &lt;a href="https://kefcore.masesgroup.com/articles/options.html" rel="noopener noreferrer"&gt;kefcore.masesgroup.com/articles/options.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Supported backends&lt;/strong&gt; : &lt;a href="https://kefcore.masesgroup.com/articles/backends.html" rel="noopener noreferrer"&gt;kefcore.masesgroup.com/articles/backends.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Getting started&lt;/strong&gt; : &lt;a href="https://kefcore.masesgroup.com/articles/gettingstarted.html" rel="noopener noreferrer"&gt;kefcore.masesgroup.com/articles/gettingstarted.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GitHub&lt;/strong&gt; : &lt;a href="https://github.com/masesgroup/KEFCore" rel="noopener noreferrer"&gt;masesgroup/KEFCore&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;KAFKA is a registered trademark of The Apache Software Foundation. MASES Group has no affiliation with and is not endorsed by The Apache Software Foundation.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>sasl</category>
      <category>apachekafka</category>
      <category>tls</category>
      <category>entityframeworkcore</category>
    </item>
  </channel>
</rss>
