├── .editorconfig ├── .gitattributes ├── .gitignore ├── MassTransitKafkaDemo.sln ├── MassTransitKafkaDemo ├── Consumers │ ├── TaskCompletedConsumer.cs │ ├── TaskEventConsumer.cs │ ├── TaskRequestedConsumer.cs │ └── TaskStartedConsumer.cs ├── Demo │ └── DemoProducer.cs ├── Infrastructure │ └── AvroSerializers │ │ ├── IReaderWrapper.cs │ │ ├── ISerializerWrapper.cs │ │ ├── MultipleTypeConfig.cs │ │ ├── MultipleTypeConfigBuilder.cs │ │ ├── MultipleTypeDeserializer.cs │ │ ├── MultipleTypeInfo.cs │ │ ├── MultipleTypeSerializer.cs │ │ ├── ReaderWrapper.cs │ │ └── SerializerWrapper.cs ├── MassTransitKafkaDemo.csproj ├── Messages │ ├── ITaskEvent.cs │ ├── TaskCompleted.cs │ ├── TaskRequested.cs │ └── TaskStarted.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── TaskCompleted.V1.avsc ├── TaskEvent.V1.avsc ├── TaskRequested.V1.avsc ├── TaskStarted.V1.avsc ├── appsettings.Development.json └── appsettings.json ├── UNLICENSE.txt ├── docker-compose.yml └── readme.md /.editorconfig: -------------------------------------------------------------------------------- 1 | # Version: 1.1.0 (Using https://semver.org/) 2 | # See http://EditorConfig.org for more information about .editorconfig files. 3 | # See https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference for an up to date list of all editorconfig values that Visual Studio understands 4 | # See https://github.com/RehanSaeed/EditorConfig for a well maintained example editorconfig file 5 | 6 | ########################################## 7 | # Preface 8 | ########################################## 9 | # The general conventions follow that of the following Microsoft Guidelines: 10 | # Design Guidelines https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/ 11 | # Naming Guidenlines https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/naming-guidelines 12 | # Stylecop rulesets https://github.com/DotNetAnalyzers/StyleCopAnalyzers/tree/master/documentation 13 | 14 | # This document has been adapted from https://github.com/RehanSaeed/EditorConfig to suit Blue Prism's own internal syles and conventions. Thise closely aligns with the above, with only the following changes: 15 | # Use of this./Me. is discouraged 16 | # Private fields must be prefixed with an underscore 17 | # Using statements are suggested to be outside of the namespace declaration 18 | # Private fields within .vb files are m-prefixed 19 | 20 | ########################################## 21 | # Common Settings 22 | ########################################## 23 | 24 | # This file is the top-most EditorConfig file 25 | root = true 26 | 27 | # All Files 28 | [*] 29 | charset = utf-8 30 | indent_style = space 31 | indent_size = 4 32 | insert_final_newline = true 33 | trim_trailing_whitespace = true 34 | 35 | ########################################## 36 | # File Extension Settings 37 | ########################################## 38 | 39 | # Visual Studio Solution Files 40 | [*.sln] 41 | indent_style = tab 42 | 43 | # Visual Studio XML Project Files 44 | [*.{csproj,vbproj,vcxproj.filters,proj,projitems,shproj}] 45 | indent_size = 2 46 | 47 | # XML Configuration Files 48 | [*.{xml,config,props,targets,nuspec,resx,ruleset,vsixmanifest,vsct}] 49 | indent_size = 2 50 | 51 | # JSON Files 52 | [*.{json,json5,webmanifest}] 53 | indent_size = 2 54 | 55 | # YAML Files 56 | [*.{yml,yaml}] 57 | indent_size = 2 58 | 59 | # Markdown Files 60 | [*.md] 61 | trim_trailing_whitespace = false 62 | 63 | # Web Files 64 | [*.{htm,html,js,jsm,ts,tsx,css,sass,scss,less,svg,vue}] 65 | indent_size = 2 66 | 67 | # Batch Files 68 | [*.{cmd,bat}] 69 | end_of_line = crlf 70 | 71 | # Bash Files 72 | [*.sh] 73 | end_of_line = lf 74 | 75 | # Makefiles 76 | [Makefile] 77 | indent_style = tab 78 | 79 | ########################################## 80 | # .NET Language Conventions 81 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions 82 | ########################################## 83 | 84 | # .NET Code Style Settings 85 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#net-code-style-settings 86 | [*.{cs,csx,cake,vb,vbx}] 87 | # "this." and "Me." qualifiers 88 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#this-and-me 89 | dotnet_style_qualification_for_field = false:warning 90 | dotnet_style_qualification_for_property = false:warning 91 | dotnet_style_qualification_for_method = false:warning 92 | dotnet_style_qualification_for_event = false:warning 93 | # Language keywords instead of framework type names for type references 94 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#language-keywords 95 | dotnet_style_predefined_type_for_locals_parameters_members = true:warning 96 | dotnet_style_predefined_type_for_member_access = true:warning 97 | # Modifier preferences 98 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#normalize-modifiers 99 | dotnet_style_require_accessibility_modifiers = always:warning 100 | csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async 101 | visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async 102 | dotnet_style_readonly_field = true:warning 103 | # Parentheses preferences 104 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#parentheses-preferences 105 | dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning 106 | dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning 107 | dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning 108 | dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion 109 | # Expression-level preferences 110 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#expression-level-preferences 111 | dotnet_style_object_initializer = true:warning 112 | dotnet_style_collection_initializer = true:warning 113 | dotnet_style_explicit_tuple_names = true:warning 114 | dotnet_style_prefer_inferred_tuple_names = true:warning 115 | dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning 116 | dotnet_style_prefer_auto_properties = true:warning 117 | dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning 118 | dotnet_style_prefer_conditional_expression_over_assignment = false:suggestion 119 | dotnet_style_prefer_conditional_expression_over_return = false:suggestion 120 | dotnet_style_prefer_compound_assignment = true:warning 121 | # Null-checking preferences 122 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#null-checking-preferences 123 | dotnet_style_coalesce_expression = true:warning 124 | dotnet_style_null_propagation = true:warning 125 | # Parameter preferences 126 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#parameter-preferences 127 | dotnet_code_quality_unused_parameters = all:warning 128 | # More style options (Undocumented) 129 | # https://github.com/MicrosoftDocs/visualstudio-docs/issues/3641 130 | dotnet_style_operator_placement_when_wrapping = end_of_line 131 | # https://github.com/dotnet/roslyn/pull/40070 132 | dotnet_style_prefer_simplified_interpolation = true:warning 133 | 134 | # C# Code Style Settings 135 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#c-code-style-settings 136 | [*.{cs,csx,cake}] 137 | # Implicit and explicit types 138 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#implicit-and-explicit-types 139 | csharp_style_var_for_built_in_types = true:warning 140 | csharp_style_var_when_type_is_apparent = true:warning 141 | csharp_style_var_elsewhere = true:warning 142 | # Expression-bodied members 143 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#expression-bodied-members 144 | csharp_style_expression_bodied_methods = true:suggestion 145 | csharp_style_expression_bodied_constructors = true:suggestion 146 | csharp_style_expression_bodied_operators = true:suggestion 147 | csharp_style_expression_bodied_properties = true:suggestion 148 | csharp_style_expression_bodied_indexers = true:suggestion 149 | csharp_style_expression_bodied_accessors = true:suggestion 150 | csharp_style_expression_bodied_lambdas = true:suggestion 151 | csharp_style_expression_bodied_local_functions = true:suggestion 152 | # Pattern matching 153 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#pattern-matching 154 | csharp_style_pattern_matching_over_is_with_cast_check = true:warning 155 | csharp_style_pattern_matching_over_as_with_null_check = true:warning 156 | # Inlined variable declarations 157 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#inlined-variable-declarations 158 | csharp_style_inlined_variable_declaration = true:warning 159 | # Expression-level preferences 160 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#expression-level-preferences 161 | csharp_prefer_simple_default_expression = true:warning 162 | # "Null" checking preferences 163 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#c-null-checking-preferences 164 | csharp_style_throw_expression = true:warning 165 | csharp_style_conditional_delegate_call = true:warning 166 | # Code block preferences 167 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#code-block-preferences 168 | csharp_prefer_braces = true:warning 169 | # Unused value preferences 170 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#unused-value-preferences 171 | csharp_style_unused_value_expression_statement_preference = discard_variable:suggestion 172 | csharp_style_unused_value_assignment_preference = discard_variable:suggestion 173 | # Index and range preferences 174 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#index-and-range-preferences 175 | csharp_style_prefer_index_operator = true:warning 176 | csharp_style_prefer_range_operator = true:warning 177 | # Miscellaneous preferences 178 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#miscellaneous-preferences 179 | csharp_style_deconstructed_variable_declaration = true:warning 180 | csharp_style_pattern_local_over_anonymous_function = true:warning 181 | csharp_using_directive_placement = outside_namespace:suggestion 182 | csharp_prefer_static_local_function = true:warning 183 | csharp_prefer_simple_using_statement = true:suggestion 184 | 185 | ########################################## 186 | # .NET Formatting Conventions 187 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-code-style-settings-reference#formatting-conventions 188 | ########################################## 189 | 190 | # Organize usings 191 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#organize-using-directives 192 | dotnet_sort_system_directives_first = true 193 | # Newline options 194 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#new-line-options 195 | csharp_new_line_before_open_brace = all 196 | csharp_new_line_before_else = true 197 | csharp_new_line_before_catch = true 198 | csharp_new_line_before_finally = true 199 | csharp_new_line_before_members_in_object_initializers = true 200 | csharp_new_line_before_members_in_anonymous_types = true 201 | csharp_new_line_between_query_expression_clauses = true 202 | # Indentation options 203 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#indentation-options 204 | csharp_indent_case_contents = true 205 | csharp_indent_switch_labels = true 206 | csharp_indent_labels = no_change 207 | csharp_indent_block_contents = true 208 | csharp_indent_braces = false 209 | csharp_indent_case_contents_when_block = false 210 | # Spacing options 211 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#spacing-options 212 | csharp_space_after_cast = false 213 | csharp_space_after_keywords_in_control_flow_statements = true 214 | csharp_space_between_parentheses = false 215 | csharp_space_before_colon_in_inheritance_clause = true 216 | csharp_space_after_colon_in_inheritance_clause = true 217 | csharp_space_around_binary_operators = before_and_after 218 | csharp_space_between_method_declaration_parameter_list_parentheses = false 219 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false 220 | csharp_space_between_method_declaration_name_and_open_parenthesis = false 221 | csharp_space_between_method_call_parameter_list_parentheses = false 222 | csharp_space_between_method_call_empty_parameter_list_parentheses = false 223 | csharp_space_between_method_call_name_and_opening_parenthesis = false 224 | csharp_space_after_comma = true 225 | csharp_space_before_comma = false 226 | csharp_space_after_dot = false 227 | csharp_space_before_dot = false 228 | csharp_space_after_semicolon_in_for_statement = true 229 | csharp_space_before_semicolon_in_for_statement = false 230 | csharp_space_around_declaration_statements = false 231 | csharp_space_before_open_square_brackets = false 232 | csharp_space_between_empty_square_brackets = false 233 | csharp_space_between_square_brackets = false 234 | # Wrapping options 235 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-formatting-conventions#wrap-options 236 | csharp_preserve_single_line_statements = false 237 | csharp_preserve_single_line_blocks = true 238 | 239 | ########################################## 240 | # .NET Naming Conventions 241 | # https://docs.microsoft.com/visualstudio/ide/editorconfig-naming-conventions 242 | ########################################## 243 | 244 | [*.{cs,csx,cake,vb,vbx}] 245 | 246 | ########################################## 247 | # Styles 248 | ########################################## 249 | 250 | # camel_case_style - Define the camelCase style 251 | dotnet_naming_style.camel_case_style.capitalization = camel_case 252 | # underscore_prefixed_camel_case_style - Define the undersocre prefixed _camelCase Style 253 | dotnet_naming_style.underscore_prefixed_camel_case_style.capitalization = camel_case 254 | dotnet_naming_style.underscore_prefixed_camel_case_style.required_prefix = _ 255 | # m_prefix_pascal_case_style 256 | dotnet_naming_style.m_prefixed_pascal_case_style.capitalization = pascal_case 257 | dotnet_naming_style.m_prefixed_pascal_case_style.required_prefix = m 258 | # pascal_case_style - Define the PascalCase style 259 | dotnet_naming_style.pascal_case_style.capitalization = pascal_case 260 | # first_upper_style - The first character must start with an upper-case character 261 | dotnet_naming_style.first_upper_style.capitalization = first_word_upper 262 | # prefix_interface_with_i_style - Interfaces must be PascalCase and the first character of an interface must be an 'I' 263 | dotnet_naming_style.prefix_interface_with_i_style.capitalization = pascal_case 264 | dotnet_naming_style.prefix_interface_with_i_style.required_prefix = I 265 | # prefix_type_parameters_with_t_style - Generic Type Parameters must be PascalCase and the first character must be a 'T' 266 | dotnet_naming_style.prefix_type_parameters_with_t_style.capitalization = pascal_case 267 | dotnet_naming_style.prefix_type_parameters_with_t_style.required_prefix = T 268 | # disallowed_style - Anything that has this style applied is marked as disallowed 269 | dotnet_naming_style.disallowed_style.capitalization = pascal_case 270 | dotnet_naming_style.disallowed_style.required_prefix = ____RULE_VIOLATION____ 271 | dotnet_naming_style.disallowed_style.required_suffix = ____RULE_VIOLATION____ 272 | # internal_error_style - This style should never occur... if it does, it indicates a bug in file or in the parser using the file 273 | dotnet_naming_style.internal_error_style.capitalization = pascal_case 274 | dotnet_naming_style.internal_error_style.required_prefix = ____INTERNAL_ERROR____ 275 | dotnet_naming_style.internal_error_style.required_suffix = ____INTERNAL_ERROR____ 276 | 277 | ########################################## 278 | # .NET Design Guideline Field Naming Rules 279 | # Naming rules for fields follow the .NET Framework design guidelines 280 | # https://docs.microsoft.com/dotnet/standard/design-guidelines/index 281 | ########################################## 282 | 283 | # All public/protected/protected_internal constant fields must be PascalCase 284 | # https://docs.microsoft.com/dotnet/standard/design-guidelines/field 285 | dotnet_naming_symbols.public_protected_constant_fields_group.applicable_accessibilities = public, protected, protected_internal 286 | dotnet_naming_symbols.public_protected_constant_fields_group.required_modifiers = const 287 | dotnet_naming_symbols.public_protected_constant_fields_group.applicable_kinds = field 288 | dotnet_naming_rule.public_protected_constant_fields_must_be_pascal_case_rule.symbols = public_protected_constant_fields_group 289 | dotnet_naming_rule.public_protected_constant_fields_must_be_pascal_case_rule.style = pascal_case_style 290 | dotnet_naming_rule.public_protected_constant_fields_must_be_pascal_case_rule.severity = warning 291 | 292 | # All public/protected/protected_internal static readonly fields must be PascalCase 293 | # https://docs.microsoft.com/dotnet/standard/design-guidelines/field 294 | dotnet_naming_symbols.public_protected_static_readonly_fields_group.applicable_accessibilities = public, protected, protected_internal 295 | dotnet_naming_symbols.public_protected_static_readonly_fields_group.required_modifiers = static, readonly 296 | dotnet_naming_symbols.public_protected_static_readonly_fields_group.applicable_kinds = field 297 | dotnet_naming_rule.public_protected_static_readonly_fields_must_be_pascal_case_rule.symbols = public_protected_static_readonly_fields_group 298 | dotnet_naming_rule.public_protected_static_readonly_fields_must_be_pascal_case_rule.style = pascal_case_style 299 | dotnet_naming_rule.public_protected_static_readonly_fields_must_be_pascal_case_rule.severity = warning 300 | 301 | # No other public/protected/protected_internal fields are allowed 302 | # https://docs.microsoft.com/dotnet/standard/design-guidelines/field 303 | dotnet_naming_symbols.other_public_protected_fields_group.applicable_accessibilities = public, protected, protected_internal 304 | dotnet_naming_symbols.other_public_protected_fields_group.applicable_kinds = field 305 | dotnet_naming_rule.other_public_protected_fields_disallowed_rule.symbols = other_public_protected_fields_group 306 | dotnet_naming_rule.other_public_protected_fields_disallowed_rule.style = disallowed_style 307 | dotnet_naming_rule.other_public_protected_fields_disallowed_rule.severity = error 308 | 309 | ########################################## 310 | # StyleCop Field Naming Rules 311 | # Naming rules for fields follow the StyleCop analyzers 312 | # This does not override any rules using disallowed_style above 313 | # https://github.com/DotNetAnalyzers/StyleCopAnalyzers 314 | ########################################## 315 | 316 | # All constant fields must be PascalCase 317 | # https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1303.md 318 | dotnet_naming_symbols.stylecop_constant_fields_group.applicable_accessibilities = public, internal, protected_internal, protected, private_protected, private 319 | dotnet_naming_symbols.stylecop_constant_fields_group.required_modifiers = const 320 | dotnet_naming_symbols.stylecop_constant_fields_group.applicable_kinds = field 321 | dotnet_naming_rule.stylecop_constant_fields_must_be_pascal_case_rule.symbols = stylecop_constant_fields_group 322 | dotnet_naming_rule.stylecop_constant_fields_must_be_pascal_case_rule.style = pascal_case_style 323 | dotnet_naming_rule.stylecop_constant_fields_must_be_pascal_case_rule.severity = warning 324 | 325 | # All static readonly fields must be PascalCase 326 | # https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1311.md 327 | dotnet_naming_symbols.stylecop_static_readonly_fields_group.applicable_accessibilities = public, internal, protected_internal, protected, private_protected, private 328 | dotnet_naming_symbols.stylecop_static_readonly_fields_group.required_modifiers = static, readonly 329 | dotnet_naming_symbols.stylecop_static_readonly_fields_group.applicable_kinds = field 330 | dotnet_naming_rule.stylecop_static_readonly_fields_must_be_pascal_case_rule.symbols = stylecop_static_readonly_fields_group 331 | dotnet_naming_rule.stylecop_static_readonly_fields_must_be_pascal_case_rule.style = pascal_case_style 332 | dotnet_naming_rule.stylecop_static_readonly_fields_must_be_pascal_case_rule.severity = warning 333 | 334 | # No non-private instance fields are allowed 335 | # https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1401.md 336 | dotnet_naming_symbols.stylecop_fields_must_be_private_group.applicable_accessibilities = public, internal, protected_internal, protected, private_protected 337 | dotnet_naming_symbols.stylecop_fields_must_be_private_group.applicable_kinds = field 338 | dotnet_naming_rule.stylecop_instance_fields_must_be_private_rule.symbols = stylecop_fields_must_be_private_group 339 | dotnet_naming_rule.stylecop_instance_fields_must_be_private_rule.style = disallowed_style 340 | dotnet_naming_rule.stylecop_instance_fields_must_be_private_rule.severity = error 341 | 342 | [*.{cs,csx,cake}] 343 | # C# Only 344 | # Private fields must be camelCase and prefixed with an underscorek, i.e. _someVariable 345 | # NOTE THIS IS A DEVIATION FROM STYLECOP # 346 | dotnet_naming_symbols.stylecop_private_fields_group.applicable_accessibilities = private 347 | dotnet_naming_symbols.stylecop_private_fields_group.applicable_kinds = field 348 | dotnet_naming_rule.stylecop_private_fields_must_be_camel_case_rule.symbols = stylecop_private_fields_group 349 | dotnet_naming_rule.stylecop_private_fields_must_be_camel_case_rule.style = underscore_prefixed_camel_case_style 350 | dotnet_naming_rule.stylecop_private_fields_must_be_camel_case_rule.severity = warning 351 | 352 | [*.{vb,vbx}] 353 | # VB Only 354 | # Private fields must be PascalCase and prefixed with an m, i.e. mSomeVariable 355 | # NOTE THIS IS A DEVIATION FROM STYLECOP # 356 | dotnet_naming_symbols.stylecop_private_fields_group.applicable_accessibilities = private 357 | dotnet_naming_symbols.stylecop_private_fields_group.applicable_kinds = field 358 | dotnet_naming_rule.vb_private_fields_must_be_m_prefixed_rule.symbols = stylecop_private_fields_group 359 | dotnet_naming_rule.vb_private_fields_must_be_m_prefixed_rule.style = m_prefixed_pascal_case_style 360 | dotnet_naming_rule.vb_private_fields_must_be_m_prefixed_rule.severity = warning 361 | 362 | 363 | # Local variables must be camelCase 364 | # https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1312.md 365 | dotnet_naming_symbols.stylecop_local_fields_group.applicable_accessibilities = local 366 | dotnet_naming_symbols.stylecop_local_fields_group.applicable_kinds = local 367 | dotnet_naming_rule.stylecop_local_fields_must_be_camel_case_rule.symbols = stylecop_local_fields_group 368 | dotnet_naming_rule.stylecop_local_fields_must_be_camel_case_rule.style = camel_case_style 369 | dotnet_naming_rule.stylecop_local_fields_must_be_camel_case_rule.severity = silent 370 | 371 | # This rule should never fire. However, it's included for at least two purposes: 372 | # First, it helps to understand, reason about, and root-case certain types of issues, such as bugs in .editorconfig parsers. 373 | # Second, it helps to raise immediate awareness if a new field type is added (as occurred recently in C#). 374 | dotnet_naming_symbols.sanity_check_uncovered_field_case_group.applicable_accessibilities = * 375 | dotnet_naming_symbols.sanity_check_uncovered_field_case_group.applicable_kinds = field 376 | dotnet_naming_rule.sanity_check_uncovered_field_case_rule.symbols = sanity_check_uncovered_field_case_group 377 | dotnet_naming_rule.sanity_check_uncovered_field_case_rule.style = internal_error_style 378 | dotnet_naming_rule.sanity_check_uncovered_field_case_rule.severity = error 379 | 380 | 381 | ########################################## 382 | # Other Naming Rules 383 | ########################################## 384 | 385 | # All of the following must be PascalCase: 386 | # - Namespaces 387 | # https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-namespaces 388 | # https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1300.md 389 | # - Classes and Enumerations 390 | # https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces 391 | # https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1300.md 392 | # - Delegates 393 | # https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces#names-of-common-types 394 | # - Constructors, Properties, Events, Methods 395 | # https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-type-members 396 | dotnet_naming_symbols.element_group.applicable_kinds = namespace, class, enum, struct, delegate, event, method, property 397 | dotnet_naming_rule.element_rule.symbols = element_group 398 | dotnet_naming_rule.element_rule.style = pascal_case_style 399 | dotnet_naming_rule.element_rule.severity = warning 400 | 401 | # Interfaces use PascalCase and are prefixed with uppercase 'I' 402 | # https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces 403 | dotnet_naming_symbols.interface_group.applicable_kinds = interface 404 | dotnet_naming_rule.interface_rule.symbols = interface_group 405 | dotnet_naming_rule.interface_rule.style = prefix_interface_with_i_style 406 | dotnet_naming_rule.interface_rule.severity = warning 407 | 408 | # Generics Type Parameters use PascalCase and are prefixed with uppercase 'T' 409 | # https://docs.microsoft.com/dotnet/standard/design-guidelines/names-of-classes-structs-and-interfaces 410 | dotnet_naming_symbols.type_parameter_group.applicable_kinds = type_parameter 411 | dotnet_naming_rule.type_parameter_rule.symbols = type_parameter_group 412 | dotnet_naming_rule.type_parameter_rule.style = prefix_type_parameters_with_t_style 413 | dotnet_naming_rule.type_parameter_rule.severity = warning 414 | 415 | # Function parameters use camelCase 416 | # https://docs.microsoft.com/dotnet/standard/design-guidelines/naming-parameters 417 | dotnet_naming_symbols.parameters_group.applicable_kinds = parameter 418 | dotnet_naming_rule.parameters_rule.symbols = parameters_group 419 | dotnet_naming_rule.parameters_rule.style = camel_case_style 420 | dotnet_naming_rule.parameters_rule.severity = warning -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.vspscc 94 | *.vssscc 95 | .builds 96 | *.pidb 97 | *.svclog 98 | *.scc 99 | 100 | # Chutzpah Test files 101 | _Chutzpah* 102 | 103 | # Visual C++ cache files 104 | ipch/ 105 | *.aps 106 | *.ncb 107 | *.opendb 108 | *.opensdf 109 | *.sdf 110 | *.cachefile 111 | *.VC.db 112 | *.VC.VC.opendb 113 | 114 | # Visual Studio profiler 115 | *.psess 116 | *.vsp 117 | *.vspx 118 | *.sap 119 | 120 | # Visual Studio Trace Files 121 | *.e2e 122 | 123 | # TFS 2012 Local Workspace 124 | $tf/ 125 | 126 | # Guidance Automation Toolkit 127 | *.gpState 128 | 129 | # ReSharper is a .NET coding add-in 130 | _ReSharper*/ 131 | *.[Rr]e[Ss]harper 132 | *.DotSettings.user 133 | 134 | # TeamCity is a build add-in 135 | _TeamCity* 136 | 137 | # DotCover is a Code Coverage Tool 138 | *.dotCover 139 | 140 | # AxoCover is a Code Coverage Tool 141 | .axoCover/* 142 | !.axoCover/settings.json 143 | 144 | # Coverlet is a free, cross platform Code Coverage Tool 145 | coverage*.json 146 | coverage*.xml 147 | coverage*.info 148 | 149 | # Visual Studio code coverage results 150 | *.coverage 151 | *.coveragexml 152 | 153 | # NCrunch 154 | _NCrunch_* 155 | .*crunch*.local.xml 156 | nCrunchTemp_* 157 | 158 | # MightyMoose 159 | *.mm.* 160 | AutoTest.Net/ 161 | 162 | # Web workbench (sass) 163 | .sass-cache/ 164 | 165 | # Installshield output folder 166 | [Ee]xpress/ 167 | 168 | # DocProject is a documentation generator add-in 169 | DocProject/buildhelp/ 170 | DocProject/Help/*.HxT 171 | DocProject/Help/*.HxC 172 | DocProject/Help/*.hhc 173 | DocProject/Help/*.hhk 174 | DocProject/Help/*.hhp 175 | DocProject/Help/Html2 176 | DocProject/Help/html 177 | 178 | # Click-Once directory 179 | publish/ 180 | 181 | # Publish Web Output 182 | *.[Pp]ublish.xml 183 | *.azurePubxml 184 | # Note: Comment the next line if you want to checkin your web deploy settings, 185 | # but database connection strings (with potential passwords) will be unencrypted 186 | *.pubxml 187 | *.publishproj 188 | 189 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 190 | # checkin your Azure Web App publish settings, but sensitive information contained 191 | # in these scripts will be unencrypted 192 | PublishScripts/ 193 | 194 | # NuGet Packages 195 | *.nupkg 196 | # NuGet Symbol Packages 197 | *.snupkg 198 | # The packages folder can be ignored because of Package Restore 199 | **/[Pp]ackages/* 200 | # except build/, which is used as an MSBuild target. 201 | !**/[Pp]ackages/build/ 202 | # Uncomment if necessary however generally it will be regenerated when needed 203 | #!**/[Pp]ackages/repositories.config 204 | # NuGet v3's project.json files produces more ignorable files 205 | *.nuget.props 206 | *.nuget.targets 207 | 208 | # Microsoft Azure Build Output 209 | csx/ 210 | *.build.csdef 211 | 212 | # Microsoft Azure Emulator 213 | ecf/ 214 | rcf/ 215 | 216 | # Windows Store app package directories and files 217 | AppPackages/ 218 | BundleArtifacts/ 219 | Package.StoreAssociation.xml 220 | _pkginfo.txt 221 | *.appx 222 | *.appxbundle 223 | *.appxupload 224 | 225 | # Visual Studio cache files 226 | # files ending in .cache can be ignored 227 | *.[Cc]ache 228 | # but keep track of directories ending in .cache 229 | !?*.[Cc]ache/ 230 | 231 | # Others 232 | ClientBin/ 233 | ~$* 234 | *~ 235 | *.dbmdl 236 | *.dbproj.schemaview 237 | *.jfm 238 | *.pfx 239 | *.publishsettings 240 | orleans.codegen.cs 241 | 242 | # Including strong name files can present a security risk 243 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 244 | #*.snk 245 | 246 | # Since there are multiple workflows, uncomment next line to ignore bower_components 247 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 248 | #bower_components/ 249 | 250 | # RIA/Silverlight projects 251 | Generated_Code/ 252 | 253 | # Backup & report files from converting an old project file 254 | # to a newer Visual Studio version. Backup files are not needed, 255 | # because we have git ;-) 256 | _UpgradeReport_Files/ 257 | Backup*/ 258 | UpgradeLog*.XML 259 | UpgradeLog*.htm 260 | ServiceFabricBackup/ 261 | *.rptproj.bak 262 | 263 | # SQL Server files 264 | *.mdf 265 | *.ldf 266 | *.ndf 267 | 268 | # Business Intelligence projects 269 | *.rdl.data 270 | *.bim.layout 271 | *.bim_*.settings 272 | *.rptproj.rsuser 273 | *- [Bb]ackup.rdl 274 | *- [Bb]ackup ([0-9]).rdl 275 | *- [Bb]ackup ([0-9][0-9]).rdl 276 | 277 | # Microsoft Fakes 278 | FakesAssemblies/ 279 | 280 | # GhostDoc plugin setting file 281 | *.GhostDoc.xml 282 | 283 | # Node.js Tools for Visual Studio 284 | .ntvs_analysis.dat 285 | node_modules/ 286 | 287 | # Visual Studio 6 build log 288 | *.plg 289 | 290 | # Visual Studio 6 workspace options file 291 | *.opt 292 | 293 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 294 | *.vbw 295 | 296 | # Visual Studio LightSwitch build output 297 | **/*.HTMLClient/GeneratedArtifacts 298 | **/*.DesktopClient/GeneratedArtifacts 299 | **/*.DesktopClient/ModelManifest.xml 300 | **/*.Server/GeneratedArtifacts 301 | **/*.Server/ModelManifest.xml 302 | _Pvt_Extensions 303 | 304 | # Paket dependency manager 305 | .paket/paket.exe 306 | paket-files/ 307 | 308 | # FAKE - F# Make 309 | .fake/ 310 | 311 | # CodeRush personal settings 312 | .cr/personal 313 | 314 | # Python Tools for Visual Studio (PTVS) 315 | __pycache__/ 316 | *.pyc 317 | 318 | # Cake - Uncomment if you are using it 319 | # tools/** 320 | # !tools/packages.config 321 | 322 | # Tabs Studio 323 | *.tss 324 | 325 | # Telerik's JustMock configuration file 326 | *.jmconfig 327 | 328 | # BizTalk build output 329 | *.btp.cs 330 | *.btm.cs 331 | *.odx.cs 332 | *.xsd.cs 333 | 334 | # OpenCover UI analysis results 335 | OpenCover/ 336 | 337 | # Azure Stream Analytics local run output 338 | ASALocalRun/ 339 | 340 | # MSBuild Binary and Structured Log 341 | *.binlog 342 | 343 | # NVidia Nsight GPU debugger configuration file 344 | *.nvuser 345 | 346 | # MFractors (Xamarin productivity tool) working folder 347 | .mfractor/ 348 | 349 | # Local History for Visual Studio 350 | .localhistory/ 351 | 352 | # BeatPulse healthcheck temp database 353 | healthchecksdb 354 | 355 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 356 | MigrationBackup/ 357 | 358 | # Ionide (cross platform F# VS Code tools) working folder 359 | .ionide/ 360 | 361 | # Fody - auto-generated XML schema 362 | FodyWeavers.xsd 363 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31025.194 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MassTransitKafkaDemo", "MassTransitKafkaDemo\MassTransitKafkaDemo.csproj", "{E487E5F8-4AE3-4B69-BDFA-89E4876D3F9A}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C34B9109-7978-46B0-BF06-6157F797DDBE}" 9 | ProjectSection(SolutionItems) = preProject 10 | .editorconfig = .editorconfig 11 | docker-compose.yml = docker-compose.yml 12 | readme.md = readme.md 13 | EndProjectSection 14 | EndProject 15 | Global 16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 17 | Debug|Any CPU = Debug|Any CPU 18 | Release|Any CPU = Release|Any CPU 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {E487E5F8-4AE3-4B69-BDFA-89E4876D3F9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 22 | {E487E5F8-4AE3-4B69-BDFA-89E4876D3F9A}.Debug|Any CPU.Build.0 = Debug|Any CPU 23 | {E487E5F8-4AE3-4B69-BDFA-89E4876D3F9A}.Release|Any CPU.ActiveCfg = Release|Any CPU 24 | {E487E5F8-4AE3-4B69-BDFA-89E4876D3F9A}.Release|Any CPU.Build.0 = Release|Any CPU 25 | EndGlobalSection 26 | GlobalSection(SolutionProperties) = preSolution 27 | HideSolutionNode = FALSE 28 | EndGlobalSection 29 | GlobalSection(ExtensibilityGlobals) = postSolution 30 | SolutionGuid = {A19A56D9-9E18-4D6E-9CF8-BC0279F5D9DB} 31 | EndGlobalSection 32 | EndGlobal 33 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Consumers/TaskCompletedConsumer.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using MassTransit; 3 | using MassTransitKafkaDemo.Messages; 4 | using Microsoft.Extensions.Logging; 5 | 6 | namespace MassTransitKafkaDemo.Consumers 7 | { 8 | public class TaskCompletedConsumer : IConsumer 9 | { 10 | private readonly ILogger _logger; 11 | 12 | public TaskCompletedConsumer(ILogger logger) 13 | { 14 | _logger = logger; 15 | } 16 | 17 | public async Task Consume(ConsumeContext context) 18 | { 19 | var message = context.Message; 20 | _logger.LogInformation($"Task {message.Id} completed at {message.CompletedDate}"); 21 | await Task.CompletedTask; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Consumers/TaskEventConsumer.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using MassTransit; 3 | using MassTransitKafkaDemo.Messages; 4 | using Microsoft.Extensions.Logging; 5 | 6 | namespace MassTransitKafkaDemo.Consumers 7 | { 8 | /// 9 | /// Example of 10 | /// 11 | public class TaskEventConsumer : IConsumer 12 | { 13 | private readonly ILogger _logger; 14 | 15 | public TaskEventConsumer(ILogger logger) 16 | { 17 | _logger = logger; 18 | } 19 | 20 | public async Task Consume(ConsumeContext context) 21 | { 22 | void LogEvent(string description) => 23 | _logger.LogInformation("{0:O} Received ({1} {2}) event: {3}", "", context.Message.Id, context.Message.GetType(), description); 24 | 25 | var message = context.Message; 26 | switch (message) 27 | { 28 | case TaskRequested requested: 29 | LogEvent($"Task requested by {requested.RequestedBy} at {requested.RequestedDate}"); 30 | break; 31 | case TaskStarted started: 32 | LogEvent($"Task started on {started.StartedOn} at {started.StartedDate}"); 33 | break; 34 | case TaskCompleted completed: 35 | LogEvent($"Task completed at {completed.CompletedDate}"); 36 | break; 37 | } 38 | await Task.CompletedTask; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Consumers/TaskRequestedConsumer.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using MassTransit; 3 | using MassTransitKafkaDemo.Messages; 4 | using Microsoft.Extensions.Logging; 5 | 6 | namespace MassTransitKafkaDemo.Consumers 7 | { 8 | public class TaskRequestedConsumer : IConsumer 9 | { 10 | private readonly ILogger _logger; 11 | 12 | public TaskRequestedConsumer(ILogger logger) 13 | { 14 | _logger = logger; 15 | } 16 | 17 | public async Task Consume(ConsumeContext context) 18 | { 19 | var message = context.Message; 20 | _logger.LogInformation($"Task {message.Id} requested by {message.RequestedBy} at {message.RequestedDate}"); 21 | await Task.CompletedTask; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Consumers/TaskStartedConsumer.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using MassTransit; 3 | using MassTransitKafkaDemo.Messages; 4 | using Microsoft.Extensions.Logging; 5 | 6 | namespace MassTransitKafkaDemo.Consumers 7 | { 8 | public class TaskStartedConsumer : IConsumer 9 | { 10 | private readonly ILogger _logger; 11 | 12 | public TaskStartedConsumer(ILogger logger) 13 | { 14 | _logger = logger; 15 | } 16 | 17 | public async Task Consume(ConsumeContext context) 18 | { 19 | var message = context.Message; 20 | _logger.LogInformation($"Task {message.Id} started on {message.StartedOn} at {message.StartedDate}"); 21 | await Task.CompletedTask; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Demo/DemoProducer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using MassTransit.KafkaIntegration; 5 | using MassTransitKafkaDemo.Messages; 6 | using Microsoft.Extensions.DependencyInjection; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace MassTransitKafkaDemo.Demo 11 | { 12 | public class DemoProducer : BackgroundService 13 | { 14 | private readonly ILogger _logger; 15 | private readonly IServiceScopeFactory _serviceScopeFactory; 16 | 17 | public DemoProducer(ILogger logger, IServiceScopeFactory serviceScopeFactory) 18 | { 19 | _logger = logger; 20 | _serviceScopeFactory = serviceScopeFactory; 21 | } 22 | 23 | protected override async Task ExecuteAsync(CancellationToken stoppingToken) 24 | { 25 | try 26 | { 27 | using var scope = _serviceScopeFactory.CreateScope(); 28 | var producer = scope.ServiceProvider.GetService>(); 29 | await Produce(producer, stoppingToken); 30 | } 31 | catch (OperationCanceledException) 32 | { 33 | _logger.LogInformation("Stopping"); 34 | } 35 | } 36 | 37 | private async Task Produce(ITopicProducer producer, CancellationToken stoppingToken) 38 | { 39 | var random = new Random(); 40 | async Task ProduceMessage(Guid key, ITaskEvent value) => 41 | await producer.Produce(key.ToString(), value, stoppingToken); 42 | 43 | async Task Wait(int min, int max) => 44 | await Task.Delay(random.Next(min, max), stoppingToken); 45 | 46 | while (true) 47 | { 48 | var id = Guid.NewGuid(); 49 | await ProduceMessage(id, new TaskRequested() 50 | { 51 | Id = id, 52 | RequestedDate = DateTime.Now, 53 | RequestedBy = "test" 54 | }); 55 | await Wait(250, 500); 56 | var startedOn = $"DEV{random.Next(1,999).ToString().PadLeft(3, '0')}"; 57 | await ProduceMessage(id, new TaskStarted() 58 | { 59 | Id = id, 60 | StartedDate = DateTime.Now, 61 | StartedOn = startedOn 62 | }); 63 | await Wait(1000, 2500); 64 | await ProduceMessage(id, new TaskCompleted() 65 | { 66 | Id = id, 67 | CompletedDate = DateTime.Now 68 | }); 69 | await Wait(1000, 2000); 70 | } 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Infrastructure/AvroSerializers/IReaderWrapper.cs: -------------------------------------------------------------------------------- 1 | using Avro.IO; 2 | 3 | namespace MassTransitKafkaDemo.Infrastructure.AvroSerializers 4 | { 5 | /// 6 | /// Wraps generic Avro SpecificReader 7 | /// 8 | public interface IReaderWrapper 9 | { 10 | object Read(BinaryDecoder decoder); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Infrastructure/AvroSerializers/ISerializerWrapper.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Confluent.Kafka; 3 | 4 | namespace MassTransitKafkaDemo.Infrastructure.AvroSerializers 5 | { 6 | /// 7 | /// Wraps generic AvroSerializer 8 | /// 9 | public interface ISerializerWrapper 10 | { 11 | Task SerializeAsync(object data, SerializationContext context); 12 | } 13 | } -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Infrastructure/AvroSerializers/MultipleTypeConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Avro; 5 | 6 | namespace MassTransitKafkaDemo.Infrastructure.AvroSerializers 7 | { 8 | /// 9 | /// Configuration used to specify the message types supported by MultipleTypeSerializer and 10 | /// MultipleTypeDeserializer. Instances are initialized using MultipleTypeConfigBuilder. 11 | /// 12 | public class MultipleTypeConfig 13 | { 14 | private readonly MultipleTypeInfo[] _types; 15 | 16 | internal MultipleTypeConfig(MultipleTypeInfo[] types) 17 | { 18 | _types = types; 19 | } 20 | 21 | public IReaderWrapper CreateReader(Schema writerSchema) 22 | { 23 | var type = _types.SingleOrDefault(x => x.Schema.Fullname == writerSchema.Fullname); 24 | if (type == null) 25 | { 26 | throw new ArgumentException($"Unexpected type {writerSchema.Fullname}. Supported types need to be added to this {nameof(MultipleTypeConfig)} instance", nameof(writerSchema)); 27 | } 28 | return type.CreateReader(writerSchema); 29 | } 30 | 31 | public IEnumerable Types => _types.AsEnumerable(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Infrastructure/AvroSerializers/MultipleTypeConfigBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Avro; 5 | using Avro.Specific; 6 | using MassTransitKafkaDemo.Messages; 7 | 8 | namespace MassTransitKafkaDemo.Infrastructure.AvroSerializers 9 | { 10 | /// 11 | /// Creates MultipleTypeConfig configuration object used by MultipleTypeDeserializer and 12 | /// MultipleTypeSerializer to set supported types. This is used when reading / writing 13 | /// different event types to the same queue. 14 | /// 15 | /// A base type shared by all event types. This is purely to support 16 | /// MassTransit implementation (see note in ) 17 | public class MultipleTypeConfigBuilder 18 | { 19 | private readonly List _types = new(); 20 | 21 | /// 22 | /// Adds details about a type of message that can be deserialized by MultipleTypeDeserializer. 23 | /// This must be a type generated using the avrogen.exe tool. 24 | /// 25 | /// 26 | /// The Avro schema used to read the object (available via the generated _SCHEMA field 27 | /// 28 | public MultipleTypeConfigBuilder AddType(Schema readerSchema) 29 | where T : TBase, ISpecificRecord 30 | { 31 | if (readerSchema is null) 32 | { 33 | throw new ArgumentNullException(nameof(readerSchema)); 34 | } 35 | 36 | if (_types.Any(x => x.Schema.Fullname == readerSchema.Fullname)) 37 | { 38 | throw new ArgumentException($"A type based on schema with the full name \"{readerSchema.Fullname}\" has already been added"); 39 | } 40 | var messageType = typeof(T); 41 | var mapping = new MultipleTypeInfo(messageType, readerSchema); 42 | _types.Add(mapping); 43 | return this; 44 | } 45 | 46 | public MultipleTypeConfig Build() => new(_types.ToArray()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Infrastructure/AvroSerializers/MultipleTypeDeserializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Net; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | using Avro.IO; 9 | using Confluent.Kafka; 10 | using Confluent.SchemaRegistry; 11 | 12 | namespace MassTransitKafkaDemo.Infrastructure.AvroSerializers 13 | { 14 | /// 15 | /// Deserializes to one of multiple types generated using the avrogen.exe tool. Supported 16 | /// types need to be configured within MultipleTypeConfig. 17 | /// 18 | /// 19 | /// Expects serialization format matching Confluent.SchemaRegistry.Serdes.AvroSerializer: 20 | /// byte 0: Magic byte use to identify the protocol format. 21 | /// bytes 1-4: Unique global id of the Avro schema that was used for encoding (as registered in Confluent Schema Registry), big endian. 22 | /// following bytes: The serialized data. 23 | /// 24 | public class MultipleTypeDeserializer : IAsyncDeserializer 25 | { 26 | public const byte MagicByte = 0; 27 | private readonly ISchemaRegistryClient _schemaRegistryClient; 28 | private readonly MultipleTypeConfig _typeConfig; 29 | private readonly ConcurrentDictionary _readers = new(); 30 | private readonly SemaphoreSlim _semaphore = new(1); 31 | 32 | public MultipleTypeDeserializer(MultipleTypeConfig typeConfig, ISchemaRegistryClient schemaRegistryClient) 33 | { 34 | _typeConfig = typeConfig; 35 | _schemaRegistryClient = schemaRegistryClient; 36 | } 37 | 38 | /// 39 | /// Deserialize an object of one of the specified types from a byte array 40 | /// 41 | /// 42 | /// The raw byte data to deserialize. 43 | /// 44 | /// 45 | /// True if this is a null value. 46 | /// 47 | /// 48 | /// Context relevant to the deserialize operation. 49 | /// 50 | /// 51 | /// A that completes 52 | /// with the deserialized value. 53 | /// 54 | public async Task DeserializeAsync(ReadOnlyMemory data, bool isNull, SerializationContext context) 55 | { 56 | try 57 | { 58 | if (data.Length < 5) 59 | { 60 | throw new InvalidDataException($"Expecting data framing of length 5 bytes or more but total data size is {data.Length} bytes"); 61 | } 62 | 63 | using (var stream = new MemoryStream(data.ToArray())) 64 | using (var reader = new BinaryReader(stream)) 65 | { 66 | var magicByte = reader.ReadByte(); 67 | if (magicByte != MagicByte) 68 | { 69 | throw new InvalidDataException($"Expecting data with Confluent Schema Registry framing. Magic byte was {magicByte}, expecting {MagicByte}"); 70 | } 71 | var schemaId = IPAddress.NetworkToHostOrder(reader.ReadInt32()); 72 | 73 | var readerWrapper = await GetReader(schemaId); 74 | return (T) readerWrapper.Read(new BinaryDecoder(stream)); 75 | } 76 | } 77 | catch (AggregateException e) 78 | { 79 | throw e.InnerException; 80 | } 81 | 82 | } 83 | 84 | private async Task GetReader(int schemaId) 85 | { 86 | if (_readers.TryGetValue(schemaId, out var reader)) 87 | { 88 | return reader; 89 | } 90 | // TODO - "keyed Semaphore" to download multiple schemas in parallel (currently a similar 91 | // approach with a single semaphore is used in Confluent.SchemaRegistry.CachedSchemaRegistryClient) 92 | await _semaphore.WaitAsync().ConfigureAwait(continueOnCapturedContext: false); 93 | try 94 | { 95 | if (!_readers.TryGetValue(schemaId, out reader)) 96 | { 97 | CleanCache(); 98 | 99 | var registrySchema = await _schemaRegistryClient.GetSchemaAsync(schemaId) 100 | .ConfigureAwait(continueOnCapturedContext: false); 101 | var avroSchema = Avro.Schema.Parse(registrySchema.SchemaString); 102 | reader = _typeConfig.CreateReader(avroSchema); 103 | _readers[schemaId] = reader; 104 | } 105 | return reader; 106 | } 107 | finally 108 | { 109 | _semaphore.Release(); 110 | } 111 | } 112 | 113 | private void CleanCache() 114 | { 115 | if (_readers.Count > _schemaRegistryClient.MaxCachedSchemas) 116 | { 117 | // LRU cache would improve performance, though there is currently 118 | // equally brutal logic in Confluent.SchemaRegistry.CachedSchemaRegistryClient 119 | _readers.Clear(); 120 | } 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Infrastructure/AvroSerializers/MultipleTypeInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Avro.Specific; 3 | using Confluent.SchemaRegistry; 4 | using Confluent.SchemaRegistry.Serdes; 5 | using Schema = Avro.Schema; 6 | 7 | namespace MassTransitKafkaDemo.Infrastructure.AvroSerializers 8 | { 9 | public abstract class MultipleTypeInfo 10 | { 11 | protected MultipleTypeInfo(Type messageType, Schema schema) 12 | { 13 | MessageType = messageType ?? throw new ArgumentNullException(nameof(messageType)); 14 | Schema = schema ?? throw new ArgumentNullException(nameof(schema)); 15 | } 16 | 17 | public Type MessageType { get; } 18 | 19 | /// 20 | /// The schema used to serialize / deserialize within this application 21 | /// 22 | public Schema Schema { get; } 23 | 24 | public abstract IReaderWrapper CreateReader(Schema writerSchema); 25 | 26 | public abstract ISerializerWrapper CreateSerializer(ISchemaRegistryClient schemaRegistryClient, 27 | AvroSerializerConfig serializerConfig); 28 | } 29 | 30 | public class MultipleTypeInfo : MultipleTypeInfo 31 | where T : ISpecificRecord 32 | { 33 | public MultipleTypeInfo(Type messageType, Schema schema) : base(messageType, schema) 34 | { 35 | } 36 | 37 | public override IReaderWrapper CreateReader(Schema writerSchema) => new ReaderWrapper(writerSchema, Schema); 38 | 39 | public override ISerializerWrapper CreateSerializer(ISchemaRegistryClient schemaRegistryClient, AvroSerializerConfig serializerConfig) 40 | { 41 | var inner = new AvroSerializer(schemaRegistryClient, serializerConfig); 42 | return new SerializerWrapper(inner); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Infrastructure/AvroSerializers/MultipleTypeSerializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | using Avro.Specific; 5 | using Confluent.Kafka; 6 | using Confluent.SchemaRegistry; 7 | using Confluent.SchemaRegistry.Serdes; 8 | 9 | namespace MassTransitKafkaDemo.Infrastructure.AvroSerializers 10 | { 11 | /// 12 | /// Deserializes to one of multiple types generated using the avrogen.exe tool, delegating to a 13 | /// different AvroSerializer instance for each message type configured within MultipleTypesConfig. 14 | /// 15 | /// 16 | /// Serialization format matches Confluent.SchemaRegistry.Serdes.AvroSerializer: 17 | /// byte 0: Magic byte use to identify the protocol format. 18 | /// bytes 1-4: Unique global id of the Avro schema that was used for encoding (as registered in Confluent Schema Registry), big endian. 19 | /// following bytes: The serialized data. 20 | /// 21 | public class MultipleTypeSerializer : IAsyncSerializer 22 | { 23 | private readonly MultipleTypeConfig _typeConfig; 24 | private readonly ISchemaRegistryClient _schemaRegistryClient; 25 | private readonly AvroSerializerConfig _serializerConfig; 26 | private readonly Dictionary _serializers = new(); 27 | 28 | public MultipleTypeSerializer(MultipleTypeConfig typeConfig, 29 | ISchemaRegistryClient schemaRegistryClient, 30 | AvroSerializerConfig serializerConfig = null) 31 | { 32 | _typeConfig = typeConfig; 33 | _schemaRegistryClient = schemaRegistryClient; 34 | _serializerConfig = serializerConfig; 35 | InitialiseSerializers(); 36 | } 37 | 38 | private void InitialiseSerializers() 39 | { 40 | foreach (var typeInfo in _typeConfig.Types) 41 | { 42 | var serializer = typeInfo.CreateSerializer(_schemaRegistryClient, _serializerConfig); 43 | _serializers[typeInfo.Schema.Fullname] = serializer; 44 | } 45 | } 46 | 47 | public async Task SerializeAsync(T data, SerializationContext context) 48 | { 49 | var record = data as ISpecificRecord; 50 | if (record == null) 51 | { 52 | throw new ArgumentException($"Object being serialized is not an instance of {nameof(ISpecificRecord)}. This serializer only serializes types generated using the avrogen.exe tool.", nameof(data)); 53 | } 54 | var fullName = record.Schema.Fullname; 55 | if (!_serializers.TryGetValue(fullName, out var serializer)) 56 | { 57 | throw new ArgumentException($"Unexpected type {fullName}. All types to be serialized need to be registered in the {nameof(MultipleTypeConfig)} that is supplied to this instance of {nameof(MultipleTypeSerializer)}", nameof(data)); 58 | } 59 | return await serializer.SerializeAsync(data, context); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Infrastructure/AvroSerializers/ReaderWrapper.cs: -------------------------------------------------------------------------------- 1 | using Avro.IO; 2 | using Avro.Specific; 3 | 4 | namespace MassTransitKafkaDemo.Infrastructure.AvroSerializers 5 | { 6 | internal class ReaderWrapper : IReaderWrapper 7 | { 8 | private readonly SpecificReader _reader; 9 | 10 | public ReaderWrapper(Avro.Schema writerSchema, Avro.Schema readerSchema) 11 | { 12 | _reader = new SpecificReader(writerSchema, readerSchema); 13 | } 14 | 15 | public object Read(BinaryDecoder decoder) => _reader.Read(default, decoder); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Infrastructure/AvroSerializers/SerializerWrapper.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | using Confluent.Kafka; 3 | using Confluent.SchemaRegistry.Serdes; 4 | 5 | namespace MassTransitKafkaDemo.Infrastructure.AvroSerializers 6 | { 7 | internal class SerializerWrapper : ISerializerWrapper 8 | { 9 | private readonly AvroSerializer _inner; 10 | 11 | public SerializerWrapper(AvroSerializer inner) 12 | { 13 | _inner = inner; 14 | } 15 | 16 | public async Task SerializeAsync(object data, SerializationContext context) 17 | { 18 | return await _inner.SerializeAsync((T)data, context).ConfigureAwait(false); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/MassTransitKafkaDemo.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net5.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Messages/ITaskEvent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace MassTransitKafkaDemo.Messages 4 | { 5 | public interface ITaskEvent 6 | { 7 | Guid Id { get; } 8 | } 9 | 10 | // HACK - MassTransit doesn't like object value types so we need a custom 11 | // base type shared by our event types 12 | public partial class TaskRequested : ITaskEvent { } 13 | public partial class TaskStarted : ITaskEvent { } 14 | public partial class TaskCompleted : ITaskEvent { } 15 | } 16 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Messages/TaskCompleted.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // Generated by avrogen, version 1.10.0.0 4 | // Changes to this file may cause incorrect behavior and will be lost if code 5 | // is regenerated 6 | // 7 | // ------------------------------------------------------------------------------ 8 | namespace MassTransitKafkaDemo.Messages 9 | { 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Text; 13 | using Avro; 14 | using Avro.Specific; 15 | 16 | /// 17 | /// The event raised when a task is completed. 18 | /// 19 | public partial class TaskCompleted : ISpecificRecord 20 | { 21 | public static Schema _SCHEMA = Avro.Schema.Parse(@"{""type"":""record"",""name"":""TaskCompleted"",""namespace"":""MassTransitKafkaDemo.Messages"",""fields"":[{""name"":""Id"",""doc"":""The id of the task"",""type"":{""type"":""string"",""logicalType"":""uuid""}},{""name"":""CompletedDate"",""doc"":""The date when the task completed"",""type"":{""type"":""long"",""logicalType"":""timestamp-millis""}}]}"); 22 | /// 23 | /// The id of the task 24 | /// 25 | private System.Guid _Id; 26 | /// 27 | /// The date when the task completed 28 | /// 29 | private System.DateTime _CompletedDate; 30 | public virtual Schema Schema 31 | { 32 | get 33 | { 34 | return TaskCompleted._SCHEMA; 35 | } 36 | } 37 | /// 38 | /// The id of the task 39 | /// 40 | public System.Guid Id 41 | { 42 | get 43 | { 44 | return this._Id; 45 | } 46 | set 47 | { 48 | this._Id = value; 49 | } 50 | } 51 | /// 52 | /// The date when the task completed 53 | /// 54 | public System.DateTime CompletedDate 55 | { 56 | get 57 | { 58 | return this._CompletedDate; 59 | } 60 | set 61 | { 62 | this._CompletedDate = value; 63 | } 64 | } 65 | public virtual object Get(int fieldPos) 66 | { 67 | switch (fieldPos) 68 | { 69 | case 0: return this.Id; 70 | case 1: return this.CompletedDate; 71 | default: throw new AvroRuntimeException("Bad index " + fieldPos + " in Get()"); 72 | }; 73 | } 74 | public virtual void Put(int fieldPos, object fieldValue) 75 | { 76 | switch (fieldPos) 77 | { 78 | case 0: this.Id = (System.Guid)fieldValue; break; 79 | case 1: this.CompletedDate = (System.DateTime)fieldValue; break; 80 | default: throw new AvroRuntimeException("Bad index " + fieldPos + " in Put()"); 81 | }; 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Messages/TaskRequested.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // Generated by avrogen, version 1.10.0.0 4 | // Changes to this file may cause incorrect behavior and will be lost if code 5 | // is regenerated 6 | // 7 | // ------------------------------------------------------------------------------ 8 | namespace MassTransitKafkaDemo.Messages 9 | { 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Text; 13 | using Avro; 14 | using Avro.Specific; 15 | 16 | /// 17 | /// The event raised when a task is requested. 18 | /// 19 | public partial class TaskRequested : ISpecificRecord 20 | { 21 | public static Schema _SCHEMA = Avro.Schema.Parse(@"{""type"":""record"",""name"":""TaskRequested"",""namespace"":""MassTransitKafkaDemo.Messages"",""fields"":[{""name"":""Id"",""doc"":""The id of the task"",""type"":{""type"":""string"",""logicalType"":""uuid""}},{""name"":""RequestedDate"",""doc"":""The date when the task was requested"",""type"":{""type"":""long"",""logicalType"":""timestamp-millis""}},{""name"":""RequestedBy"",""doc"":""The name of the user that requested the task"",""type"":""string""}]}"); 22 | /// 23 | /// The id of the task 24 | /// 25 | private System.Guid _Id; 26 | /// 27 | /// The date when the task was requested 28 | /// 29 | private System.DateTime _RequestedDate; 30 | /// 31 | /// The name of the user that requested the task 32 | /// 33 | private string _RequestedBy; 34 | public virtual Schema Schema 35 | { 36 | get 37 | { 38 | return TaskRequested._SCHEMA; 39 | } 40 | } 41 | /// 42 | /// The id of the task 43 | /// 44 | public System.Guid Id 45 | { 46 | get 47 | { 48 | return this._Id; 49 | } 50 | set 51 | { 52 | this._Id = value; 53 | } 54 | } 55 | /// 56 | /// The date when the task was requested 57 | /// 58 | public System.DateTime RequestedDate 59 | { 60 | get 61 | { 62 | return this._RequestedDate; 63 | } 64 | set 65 | { 66 | this._RequestedDate = value; 67 | } 68 | } 69 | /// 70 | /// The name of the user that requested the task 71 | /// 72 | public string RequestedBy 73 | { 74 | get 75 | { 76 | return this._RequestedBy; 77 | } 78 | set 79 | { 80 | this._RequestedBy = value; 81 | } 82 | } 83 | public virtual object Get(int fieldPos) 84 | { 85 | switch (fieldPos) 86 | { 87 | case 0: return this.Id; 88 | case 1: return this.RequestedDate; 89 | case 2: return this.RequestedBy; 90 | default: throw new AvroRuntimeException("Bad index " + fieldPos + " in Get()"); 91 | }; 92 | } 93 | public virtual void Put(int fieldPos, object fieldValue) 94 | { 95 | switch (fieldPos) 96 | { 97 | case 0: this.Id = (System.Guid)fieldValue; break; 98 | case 1: this.RequestedDate = (System.DateTime)fieldValue; break; 99 | case 2: this.RequestedBy = (System.String)fieldValue; break; 100 | default: throw new AvroRuntimeException("Bad index " + fieldPos + " in Put()"); 101 | }; 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Messages/TaskStarted.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // Generated by avrogen, version 1.10.0.0 4 | // Changes to this file may cause incorrect behavior and will be lost if code 5 | // is regenerated 6 | // 7 | // ------------------------------------------------------------------------------ 8 | namespace MassTransitKafkaDemo.Messages 9 | { 10 | using System; 11 | using System.Collections.Generic; 12 | using System.Text; 13 | using Avro; 14 | using Avro.Specific; 15 | 16 | /// 17 | /// The event raised when a task is started. 18 | /// 19 | public partial class TaskStarted : ISpecificRecord 20 | { 21 | public static Schema _SCHEMA = Avro.Schema.Parse(@"{""type"":""record"",""name"":""TaskStarted"",""namespace"":""MassTransitKafkaDemo.Messages"",""fields"":[{""name"":""Id"",""doc"":""The id of the task"",""type"":{""type"":""string"",""logicalType"":""uuid""}},{""name"":""StartedDate"",""doc"":""The date when the task started"",""type"":{""type"":""long"",""logicalType"":""timestamp-millis""}},{""name"":""StartedOn"",""doc"":""The worker starting the task"",""type"":""string""}]}"); 22 | /// 23 | /// The id of the task 24 | /// 25 | private System.Guid _Id; 26 | /// 27 | /// The date when the task started 28 | /// 29 | private System.DateTime _StartedDate; 30 | /// 31 | /// The worker starting the task 32 | /// 33 | private string _StartedOn; 34 | public virtual Schema Schema 35 | { 36 | get 37 | { 38 | return TaskStarted._SCHEMA; 39 | } 40 | } 41 | /// 42 | /// The id of the task 43 | /// 44 | public System.Guid Id 45 | { 46 | get 47 | { 48 | return this._Id; 49 | } 50 | set 51 | { 52 | this._Id = value; 53 | } 54 | } 55 | /// 56 | /// The date when the task started 57 | /// 58 | public System.DateTime StartedDate 59 | { 60 | get 61 | { 62 | return this._StartedDate; 63 | } 64 | set 65 | { 66 | this._StartedDate = value; 67 | } 68 | } 69 | /// 70 | /// The worker starting the task 71 | /// 72 | public string StartedOn 73 | { 74 | get 75 | { 76 | return this._StartedOn; 77 | } 78 | set 79 | { 80 | this._StartedOn = value; 81 | } 82 | } 83 | public virtual object Get(int fieldPos) 84 | { 85 | switch (fieldPos) 86 | { 87 | case 0: return this.Id; 88 | case 1: return this.StartedDate; 89 | case 2: return this.StartedOn; 90 | default: throw new AvroRuntimeException("Bad index " + fieldPos + " in Get()"); 91 | }; 92 | } 93 | public virtual void Put(int fieldPos, object fieldValue) 94 | { 95 | switch (fieldPos) 96 | { 97 | case 0: this.Id = (System.Guid)fieldValue; break; 98 | case 1: this.StartedDate = (System.DateTime)fieldValue; break; 99 | case 2: this.StartedOn = (System.String)fieldValue; break; 100 | default: throw new AvroRuntimeException("Bad index " + fieldPos + " in Put()"); 101 | }; 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Hosting; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.Hosting; 4 | using Microsoft.Extensions.Logging; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Threading.Tasks; 9 | 10 | namespace MassTransitKafkaDemo 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | try 17 | { 18 | Console.WriteLine("Starting host"); 19 | CreateHostBuilder(args).Build().Run(); 20 | } 21 | catch (Exception exception) 22 | { 23 | Console.WriteLine("Error starting host: " + exception); 24 | throw; 25 | } 26 | } 27 | 28 | public static IHostBuilder CreateHostBuilder(string[] args) => 29 | Host.CreateDefaultBuilder(args) 30 | .ConfigureWebHostDefaults(webBuilder => 31 | { 32 | webBuilder.UseStartup(); 33 | }); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:9270", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "environmentVariables": { 14 | "ASPNETCORE_ENVIRONMENT": "Development" 15 | } 16 | }, 17 | "MassTransitKafkaDemo": { 18 | "commandName": "Project", 19 | "environmentVariables": { 20 | "ASPNETCORE_ENVIRONMENT": "Development" 21 | }, 22 | "dotnetRunMessages": "true", 23 | "applicationUrl": "http://localhost:5000" 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /MassTransitKafkaDemo/Startup.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.AspNetCore.Http; 4 | using Microsoft.Extensions.DependencyInjection; 5 | using Microsoft.Extensions.Hosting; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Threading.Tasks; 10 | using Confluent.Kafka; 11 | using Confluent.Kafka.SyncOverAsync; 12 | using Confluent.SchemaRegistry; 13 | using Confluent.SchemaRegistry.Serdes; 14 | using MassTransit; 15 | using MassTransit.KafkaIntegration; 16 | using MassTransitKafkaDemo.Consumers; 17 | using MassTransitKafkaDemo.Demo; 18 | using MassTransitKafkaDemo.Infrastructure.AvroSerializers; 19 | using MassTransitKafkaDemo.Messages; 20 | 21 | namespace MassTransitKafkaDemo 22 | { 23 | public class Startup 24 | { 25 | private const string TaskEventsTopic = "task-events"; 26 | private const string KafkaBroker = "localhost:9092"; 27 | private const string SchemaRegistryUrl = "http://localhost:8081"; 28 | 29 | public void ConfigureServices(IServiceCollection services) 30 | { 31 | var schemaRegistryConfig = new SchemaRegistryConfig { Url = SchemaRegistryUrl }; 32 | var schemaRegistryClient = new CachedSchemaRegistryClient(schemaRegistryConfig); 33 | services.AddSingleton(schemaRegistryClient); 34 | 35 | services.AddMassTransit(busConfig => 36 | { 37 | busConfig.UsingInMemory((context,config) => config.ConfigureEndpoints(context)); 38 | busConfig.AddRider(riderConfig => 39 | { 40 | // Specify supported message types here. Support is restricted to types generated via avrogen.exe 41 | // tool. Being explicit makes this a lot simpler as we can use Avro Schema objects rather than messing 42 | // around with .NET Types / reflection. 43 | var multipleTypeConfig = new MultipleTypeConfigBuilder() 44 | .AddType(TaskRequested._SCHEMA) 45 | .AddType(TaskStarted._SCHEMA) 46 | .AddType(TaskCompleted._SCHEMA) 47 | .Build(); 48 | 49 | 50 | // Set up producers - events are produced by DemoProducer hosted service 51 | riderConfig.AddProducer(TaskEventsTopic, (riderContext,producerConfig) => 52 | { 53 | // Serializer configuration. 54 | 55 | // Important: Use either SubjectNameStrategy.Record or SubjectNameStrategy.TopicRecord. 56 | // SubjectNameStrategy.Topic (default) would result in the topic schema being set based on 57 | // the first message produced. 58 | // 59 | // Note that you can restrict the range of message types for a topic by setting up the 60 | // topic schema using schema references. This hasn't yet been covered in this demo - more 61 | // details available here: 62 | // https://docs.confluent.io/platform/current/schema-registry/serdes-develop/index.html#multiple-event-types-in-the-same-topic 63 | // https://docs.confluent.io/platform/current/schema-registry/serdes-develop/serdes-avro.html#multiple-event-types-same-topic-avro 64 | // https://www.confluent.io/blog/multiple-event-types-in-the-same-kafka-topic/ 65 | var serializerConfig = new AvroSerializerConfig 66 | { 67 | SubjectNameStrategy = SubjectNameStrategy.Record, 68 | AutoRegisterSchemas = true 69 | }; 70 | 71 | var serializer = new MultipleTypeSerializer(multipleTypeConfig, schemaRegistryClient, serializerConfig); 72 | // Note that all child serializers share the same AvroSerializerConfig - separate producers could 73 | // be used for each logical set of message types (e.g. all messages produced to a certain topic) 74 | // to support varying configuration if needed. 75 | producerConfig.SetKeySerializer(new AvroSerializer(schemaRegistryClient).AsSyncOverAsync()); 76 | producerConfig.SetValueSerializer(serializer.AsSyncOverAsync()); 77 | }); 78 | 79 | // Set up consumers and consuming 80 | riderConfig.AddConsumersFromNamespaceContaining(); 81 | 82 | riderConfig.UsingKafka((riderContext,kafkaConfig) => 83 | { 84 | kafkaConfig.Host(KafkaBroker); 85 | var groupId = Guid.NewGuid().ToString(); // always start from beginning 86 | kafkaConfig.TopicEndpoint(TaskEventsTopic, groupId, topicConfig => 87 | { 88 | topicConfig.AutoOffsetReset = AutoOffsetReset.Earliest; 89 | topicConfig.SetKeyDeserializer(new AvroDeserializer(schemaRegistryClient, null).AsSyncOverAsync()); 90 | topicConfig.SetValueDeserializer( 91 | new MultipleTypeDeserializer(multipleTypeConfig, schemaRegistryClient) 92 | .AsSyncOverAsync()); 93 | topicConfig.ConfigureConsumer(riderContext); 94 | topicConfig.ConfigureConsumer(riderContext); 95 | topicConfig.ConfigureConsumer(riderContext); 96 | 97 | // Example of consuming base message type and being able to work with 98 | // concrete subclass 99 | topicConfig.ConfigureConsumer(riderContext); 100 | }); 101 | }); 102 | }); 103 | }); 104 | services.AddMassTransitHostedService(); 105 | 106 | // This fella produces the events 107 | services.AddHostedService(); 108 | } 109 | 110 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 111 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 112 | { 113 | if (env.IsDevelopment()) 114 | { 115 | app.UseDeveloperExceptionPage(); 116 | } 117 | 118 | app.UseRouting(); 119 | 120 | app.UseEndpoints(endpoints => 121 | { 122 | endpoints.MapGet("/", async context => 123 | { 124 | await context.Response.WriteAsync("Hello World!"); 125 | }); 126 | }); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/TaskCompleted.V1.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "namespace": "MassTransitKafkaDemo.Messages", 3 | "type": "record", 4 | "doc": "The event raised when a task is completed.", 5 | "name": "TaskCompleted", 6 | "fields": [ 7 | { 8 | "name": "Id", 9 | "type": 10 | { 11 | "type": "string", 12 | "logicalType": "uuid" 13 | }, 14 | "doc": "The id of the task" 15 | }, 16 | { 17 | "name": "CompletedDate", 18 | "type": 19 | { 20 | "type": "long", 21 | "logicalType": "timestamp-millis" 22 | }, 23 | "doc": "The date when the task completed" 24 | } 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/TaskEvent.V1.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "namespace": "MassTransitKafkaDemo.Messages", 3 | "type": "record", 4 | "doc": "The event raised when a task is started.", 5 | "name": "TaskStarted", 6 | "fields": [ 7 | { 8 | "name": "Id", 9 | "type": { 10 | "type": "string", 11 | "logicalType": "uuid" 12 | }, 13 | "doc": "The id of the task" 14 | }, 15 | { 16 | "name": "StartedDate", 17 | "type": { 18 | "type": "long", 19 | "logicalType": "timestamp-millis" 20 | }, 21 | "doc": "The date when the task started" 22 | }, 23 | { 24 | "name": "StartedOn", 25 | "type": "string", 26 | "doc": "The worker starting the task" 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/TaskRequested.V1.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "namespace": "MassTransitKafkaDemo.Messages", 3 | "type": "record", 4 | "doc": "The event raised when a task is requested.", 5 | "name": "TaskRequested", 6 | "fields": [ 7 | { 8 | "name": "Id", 9 | "type": { 10 | "type": "string", 11 | "logicalType": "uuid" 12 | }, 13 | "doc": "The id of the task" 14 | }, 15 | { 16 | "name": "RequestedDate", 17 | "type": { 18 | "type": "long", 19 | "logicalType": "timestamp-millis" 20 | }, 21 | "logicalType": "date", 22 | "doc": "The date when the task was requested" 23 | }, 24 | { 25 | "name": "RequestedBy", 26 | "type": "string", 27 | "doc": "The name of the user that requested the task" 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/TaskStarted.V1.avsc: -------------------------------------------------------------------------------- 1 | { 2 | "namespace": "MassTransitKafkaDemo.Messages", 3 | "type": "record", 4 | "doc": "The event raised when a task is started.", 5 | "name": "TaskStarted", 6 | "fields": [ 7 | { 8 | "name": "Id", 9 | "type": { 10 | "type": "string", 11 | "logicalType": "uuid" 12 | }, 13 | "doc": "The id of the task" 14 | }, 15 | { 16 | "name": "StartedDate", 17 | "type": { 18 | "type": "long", 19 | "logicalType": "timestamp-millis" 20 | }, 21 | "doc": "The date when the task started" 22 | }, 23 | { 24 | "name": "StartedOn", 25 | "type": "string", 26 | "doc": "The worker starting the task" 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /MassTransitKafkaDemo/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /UNLICENSE.txt: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | --- 2 | version: '2' 3 | services: 4 | zookeeper: 5 | image: confluentinc/cp-zookeeper:6.2.0 6 | hostname: zookeeper 7 | container_name: zookeeper 8 | ports: 9 | - "2181:2181" 10 | environment: 11 | ZOOKEEPER_CLIENT_PORT: 2181 12 | ZOOKEEPER_TICK_TIME: 2000 13 | 14 | broker: 15 | image: confluentinc/cp-server:6.2.0 16 | hostname: broker 17 | container_name: broker 18 | depends_on: 19 | - zookeeper 20 | ports: 21 | - "9092:9092" 22 | - "9101:9101" 23 | environment: 24 | KAFKA_BROKER_ID: 1 25 | KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181' 26 | KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT 27 | KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://localhost:9092 28 | KAFKA_METRIC_REPORTERS: io.confluent.metrics.reporter.ConfluentMetricsReporter 29 | KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 30 | KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0 31 | KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR: 1 32 | KAFKA_CONFLUENT_BALANCER_TOPIC_REPLICATION_FACTOR: 1 33 | KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 34 | KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 35 | KAFKA_JMX_PORT: 9101 36 | KAFKA_JMX_HOSTNAME: localhost 37 | KAFKA_CONFLUENT_SCHEMA_REGISTRY_URL: http://schema-registry:8081 38 | CONFLUENT_METRICS_REPORTER_BOOTSTRAP_SERVERS: broker:29092 39 | CONFLUENT_METRICS_REPORTER_TOPIC_REPLICAS: 1 40 | CONFLUENT_METRICS_ENABLE: 'true' 41 | CONFLUENT_SUPPORT_CUSTOMER_ID: 'anonymous' 42 | 43 | schema-registry: 44 | image: confluentinc/cp-schema-registry:6.2.0 45 | hostname: schema-registry 46 | container_name: schema-registry 47 | depends_on: 48 | - broker 49 | ports: 50 | - "8081:8081" 51 | environment: 52 | SCHEMA_REGISTRY_HOST_NAME: schema-registry 53 | SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: 'broker:29092' 54 | SCHEMA_REGISTRY_LISTENERS: http://0.0.0.0:8081 55 | 56 | connect: 57 | image: cnfldemos/cp-server-connect-datagen:0.5.0-6.2.0 58 | hostname: connect 59 | container_name: connect 60 | depends_on: 61 | - broker 62 | - schema-registry 63 | ports: 64 | - "8083:8083" 65 | environment: 66 | CONNECT_BOOTSTRAP_SERVERS: 'broker:29092' 67 | CONNECT_REST_ADVERTISED_HOST_NAME: connect 68 | CONNECT_REST_PORT: 8083 69 | CONNECT_GROUP_ID: compose-connect-group 70 | CONNECT_CONFIG_STORAGE_TOPIC: docker-connect-configs 71 | CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR: 1 72 | CONNECT_OFFSET_FLUSH_INTERVAL_MS: 10000 73 | CONNECT_OFFSET_STORAGE_TOPIC: docker-connect-offsets 74 | CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR: 1 75 | CONNECT_STATUS_STORAGE_TOPIC: docker-connect-status 76 | CONNECT_STATUS_STORAGE_REPLICATION_FACTOR: 1 77 | CONNECT_KEY_CONVERTER: org.apache.kafka.connect.storage.StringConverter 78 | CONNECT_VALUE_CONVERTER: io.confluent.connect.avro.AvroConverter 79 | CONNECT_VALUE_CONVERTER_SCHEMA_REGISTRY_URL: http://schema-registry:8081 80 | # CLASSPATH required due to CC-2422 81 | CLASSPATH: /usr/share/java/monitoring-interceptors/monitoring-interceptors-6.2.0.jar 82 | CONNECT_PRODUCER_INTERCEPTOR_CLASSES: "io.confluent.monitoring.clients.interceptor.MonitoringProducerInterceptor" 83 | CONNECT_CONSUMER_INTERCEPTOR_CLASSES: "io.confluent.monitoring.clients.interceptor.MonitoringConsumerInterceptor" 84 | CONNECT_PLUGIN_PATH: "/usr/share/java,/usr/share/confluent-hub-components" 85 | CONNECT_LOG4J_LOGGERS: org.apache.zookeeper=ERROR,org.I0Itec.zkclient=ERROR,org.reflections=ERROR 86 | 87 | control-center: 88 | image: confluentinc/cp-enterprise-control-center:6.2.0 89 | hostname: control-center 90 | container_name: control-center 91 | depends_on: 92 | - broker 93 | - schema-registry 94 | - connect 95 | - ksqldb-server 96 | ports: 97 | - "9021:9021" 98 | environment: 99 | CONTROL_CENTER_BOOTSTRAP_SERVERS: 'broker:29092' 100 | CONTROL_CENTER_CONNECT_CONNECT-DEFAULT_CLUSTER: 'connect:8083' 101 | CONTROL_CENTER_KSQL_KSQLDB1_URL: "http://ksqldb-server:8088" 102 | CONTROL_CENTER_KSQL_KSQLDB1_ADVERTISED_URL: "http://localhost:8088" 103 | CONTROL_CENTER_SCHEMA_REGISTRY_URL: "http://schema-registry:8081" 104 | CONTROL_CENTER_REPLICATION_FACTOR: 1 105 | CONTROL_CENTER_INTERNAL_TOPICS_PARTITIONS: 1 106 | CONTROL_CENTER_MONITORING_INTERCEPTOR_TOPIC_PARTITIONS: 1 107 | CONFLUENT_METRICS_TOPIC_REPLICATION: 1 108 | PORT: 9021 109 | 110 | ksqldb-server: 111 | image: confluentinc/cp-ksqldb-server:6.2.0 112 | hostname: ksqldb-server 113 | container_name: ksqldb-server 114 | depends_on: 115 | - broker 116 | - connect 117 | ports: 118 | - "8088:8088" 119 | environment: 120 | KSQL_CONFIG_DIR: "/etc/ksql" 121 | KSQL_BOOTSTRAP_SERVERS: "broker:29092" 122 | KSQL_HOST_NAME: ksqldb-server 123 | KSQL_LISTENERS: "http://0.0.0.0:8088" 124 | KSQL_CACHE_MAX_BYTES_BUFFERING: 0 125 | KSQL_KSQL_SCHEMA_REGISTRY_URL: "http://schema-registry:8081" 126 | KSQL_PRODUCER_INTERCEPTOR_CLASSES: "io.confluent.monitoring.clients.interceptor.MonitoringProducerInterceptor" 127 | KSQL_CONSUMER_INTERCEPTOR_CLASSES: "io.confluent.monitoring.clients.interceptor.MonitoringConsumerInterceptor" 128 | KSQL_KSQL_CONNECT_URL: "http://connect:8083" 129 | KSQL_KSQL_LOGGING_PROCESSING_TOPIC_REPLICATION_FACTOR: 1 130 | KSQL_KSQL_LOGGING_PROCESSING_TOPIC_AUTO_CREATE: 'true' 131 | KSQL_KSQL_LOGGING_PROCESSING_STREAM_AUTO_CREATE: 'true' 132 | 133 | ksqldb-cli: 134 | image: confluentinc/cp-ksqldb-cli:6.2.0 135 | container_name: ksqldb-cli 136 | depends_on: 137 | - broker 138 | - connect 139 | - ksqldb-server 140 | entrypoint: /bin/sh 141 | tty: true 142 | 143 | ksql-datagen: 144 | image: confluentinc/ksqldb-examples:6.2.0 145 | hostname: ksql-datagen 146 | container_name: ksql-datagen 147 | depends_on: 148 | - ksqldb-server 149 | - broker 150 | - schema-registry 151 | - connect 152 | command: "bash -c 'echo Waiting for Kafka to be ready... && \ 153 | cub kafka-ready -b broker:29092 1 40 && \ 154 | echo Waiting for Confluent Schema Registry to be ready... && \ 155 | cub sr-ready schema-registry 8081 40 && \ 156 | echo Waiting a few seconds for topic creation to finish... && \ 157 | sleep 11 && \ 158 | tail -f /dev/null'" 159 | environment: 160 | KSQL_CONFIG_DIR: "/etc/ksql" 161 | STREAMS_BOOTSTRAP_SERVERS: broker:29092 162 | STREAMS_SCHEMA_REGISTRY_HOST: schema-registry 163 | STREAMS_SCHEMA_REGISTRY_PORT: 8081 164 | 165 | rest-proxy: 166 | image: confluentinc/cp-kafka-rest:6.2.0 167 | depends_on: 168 | - broker 169 | - schema-registry 170 | ports: 171 | - 8082:8082 172 | hostname: rest-proxy 173 | container_name: rest-proxy 174 | environment: 175 | KAFKA_REST_HOST_NAME: rest-proxy 176 | KAFKA_REST_BOOTSTRAP_SERVERS: 'broker:29092' 177 | KAFKA_REST_LISTENERS: "http://0.0.0.0:8082" 178 | KAFKA_REST_SCHEMA_REGISTRY_URL: 'http://schema-registry:8081' 179 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # MassTransit Kafka Demo 2 | 3 | ## Introduction 4 | 5 | Demonstrates use of MassTransit Kafka rider to produce and consume messages, including support for multiple message types on a single topic. 6 | 7 | Support for multiple event types per topic implemented via a custom Avro serializer. Note that a similar approach is needed when using the Confluent.Kafka libraries directly. See https://github.com/danmalcolm/confluent-kafka-dotnet/tree/multiple-message-types-on-topic. 8 | 9 | ## Implementation Notes 10 | 11 | 12 | ## Prerequisites 13 | 14 | Development environment requires Docker support, e.g. Docker Desktop on windows and docker compose. 15 | 16 | Execute the following from command prompt within solution directory to start Kafka infrastructure (use `docker-compose` if your version of docker does not support the compose command): 17 | 18 | `docker compose up -d` 19 | 20 | It should then be possible to run the MassTransitKafkaDemo project. 21 | 22 | ## Generating Avro classes 23 | 24 | Install the tool apache.avro.tools 1.10 or higher (Apache tool supports logical types in avsc files) 25 | 26 | This can be installed with: 27 | 28 | ``` 29 | dotnet tool install --global Apache.Avro.Tools --version 1.10.2 30 | ``` 31 | 32 | Generate types: 33 | 34 | `avrogen -s TaskRequested.V1.avsc ..\;avrogen -s TaskStarted.V1.avsc ..\;avrogen -s TaskCompleted.V1.avsc ..\;` 35 | 36 | ## Browsing schema registry 37 | 38 | Examples using Powershell. 39 | 40 | All subjects: 41 | 42 | `Invoke-RestMethod -Uri http://localhost:8081/subjects` 43 | 44 | Latest version: 45 | 46 | `Invoke-RestMethod -Uri http://localhost:8081/subjects/MassTransitKafkaDemo.Messages.TaskRequested/versions/latest | Format-List` 47 | 48 | 49 | 50 | --------------------------------------------------------------------------------