# Multiple Event types in same topic

**URL:** <https://forum.confluent.io/t/multiple-event-types-in-same-topic/1634>\
**Category:** Schema Registry\
**Created:** [30 April 2021 07:48 UTC](https://forum.confluent.io/t/multiple-event-types-in-same-topic/1634 "2021-04-30T07:48:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhisheks](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@abhisheks](https://forum.confluent.io/u/abhisheks)\
**Post date:** [30 April 2021 07:48 UTC](https://forum.confluent.io/t/multiple-event-types-in-same-topic/1634/1 "2021-04-30T07:48:27Z")

</div>

Hi,

I am trying to refer this blog and create a multi type schema using the same topic. [Multiple Event Types in the Same Kafka Topic - Revisited](https://www.confluent.io/blog/multiple-event-types-in-the-same-kafka-topic/)

Below is the schema which I have created using maven avro plugin, mvn schema-registry:register.

After registering I get the console log as :

```auto
Registered subject(emp-address-updated) with id 867 version 1
[INFO] Registered subject(emp-created) with id 868 version 1
[INFO] Registered subject(emp-department-changed) with id 869 version 1
[INFO] Registered subject(emp-types-value) with id 870 version 1

```

And the schema in the confluent control center looks like :

```auto
{
   "fields": [
     {
       "name": "employeeType",
       "type": [
         "EmpCreated",
         "EmpDepartmentChanged",
         "EmpAddressUpdated"
       ]
     }
   ],
   "name": "EmpTypes",
   "namespace": "com.domain.messaging.resource",
   "type": "record"
 }

```

When I am trying to produce an event using the below producer properties of type EmpCreated, I am getting the error mentioned below:

propeties:

```auto
key.serializer: org.apache.kafka.common.serialization.IntegerSerializer
value.serializer: io.confluent.kafka.serializers.KafkaAvroSerializer
schema.registry.url: <schema-registry-url>
auto.register.schemas: false
use.latest.version: true
value.schema.id: 870

```

error:

```auto
io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException: Schema not found; error code: 40403
	at io.confluent.kafka.schemaregistry.client.rest.RestService.sendHttpRequest(RestService.java:230) ~[kafka-schema-registry-client-5.3.0.jar:na]
	at io.confluent.kafka.schemaregistry.client.rest.RestService.httpRequest(RestService.java:256) ~[kafka-schema-registry-client-5.3.0.jar:na]
	at io.confluent.kafka.schemaregistry.client.rest.RestService.lookUpSubjectVersion(RestService.java:323) ~[kafka-schema-registry-client-5.3.0.jar:na]
	at io.confluent.kafka.schemaregistry.client.rest.RestService.lookUpSubjectVersion(RestService.java:311) ~[kafka-schema-registry-client-5.3.0.jar:na]
	at io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient.getIdFromRegistry(CachedSchemaRegistryClient.java:191) ~[kafka-schema-registry-client-5.3.0.jar:na]
	at io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient.getId(CachedSchemaRegistryClient.java:323) ~[kafka-schema-registry-client-5.3.0.jar:na]
	at io.confluent.kafka.serializers.AbstractKafkaAvroSerializer.serializeImpl(AbstractKafkaAvroSerializer.java:82) ~[kafka-avro-serializer-4.0.0.jar:na]
	at io.confluent.kafka.serializers.KafkaAvroSerializer.serialize(KafkaAvroSerializer.java:53) ~[kafka-avro-serializer-4.0.0.jar:na]
	at org.apache.kafka.common.serialization.ExtendedSerializer$Wrapper.serialize(ExtendedSerializer.java:65) ~[kafka-clients-2.0.1.jar:na]
	at org.apache.kafka.common.serialization.ExtendedSerializer$Wrapper.serialize(ExtendedSerializer.java:55) ~[kafka-clients-2.0.1.jar:na]
	at org.apache.kafka.clients.producer.KafkaProducer.doSend(KafkaProducer.java:841) ~[kafka-clients-2.0.1.jar:na]
	at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:803) ~[kafka-clients-2.0.1.jar:na]
	at org.springframework.kafka.core.DefaultKafkaProducerFactory$CloseSafeProducer.send(DefaultKafkaProducerFactory.java:444) ~[spring-kafka-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.kafka.core.KafkaTemplate.doSend(KafkaTemplate.java:381) ~[spring-kafka-2.2.5.RELEASE.jar:2.2.5.RELEASE]
	at org.springframework.kafka.core.KafkaTemplate.send(KafkaTemplate.java:218) ~[spring-kafka-2.2.5.RELEASE.jar:2.2.5.RELEAS

```

What am I missing here, could you please suggest?

---

<div class="post-metadata">

**Author:** ![gklijs](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/gklijs/32/223_2.png) [@gklijs](https://forum.confluent.io/u/gklijs)\
**Post date:** [1 May 2021 00:24 UTC](https://forum.confluent.io/t/multiple-event-types-in-same-topic/1634/2 "2021-05-01T00:24:04Z")

</div>

It depends on how you registered the schema’s. But since you want to store multiple in the same topic, it should be recordname, or topicrecordname like in [bkes-demo/clients.clj at 7d86b9b2ef2b014c0ef85b045de8559013d9e9ee · gklijs/bkes-demo · GitHub](https://github.com/gklijs/bkes-demo/blob/7d86b9b2ef2b014c0ef85b045de8559013d9e9ee/topology/src/nl/openweb/topology/clients.clj#L51).

---

<div class="post-metadata">

**Author:** ![abhisheks](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@abhisheks](https://forum.confluent.io/u/abhisheks)\
**Post date:** [3 May 2021 18:17 UTC](https://forum.confluent.io/t/multiple-event-types-in-same-topic/1634/3 "2021-05-03T18:17:36Z")

</div>

Hi,

I have used the maven schema: register to register the schema with references. Followed exactly what is mentioned in the blog below, section : “Getting started with schema references”.

> **[Multiple Event Types in the Same Kafka Topic - Revisited](https://www.confluent.io/blog/multiple-event-types-in-the-same-kafka-topic/)**
>
> Learn how to put several event types in the same Kafka topic using schema references, along with pros and cons.

As per this, the default TopicNameStrategy should work. My Subject name is emp-types-value and the topic name is emp-types.  
I am still facing the same issue of “Schema not found; error code: 40403”. Please let me know your thoughts here.

---

<div class="post-metadata">

**Author:** ![gpietro](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/gpietro/32/685_2.png) [@gpietro](https://forum.confluent.io/u/gpietro)\
**Post date:** [4 May 2021 07:00 UTC](https://forum.confluent.io/t/multiple-event-types-in-same-topic/1634/4 "2021-05-04T07:00:42Z")

</div>

> [@abhisheks](#):
>
> y Subject name is emp-types-value and the topic name is emp-types.

how is your pom file configured? Are you using spring boot?

---

<div class="post-metadata">

**Author:** ![abhisheks](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@abhisheks](https://forum.confluent.io/u/abhisheks)\
**Post date:** [4 May 2021 08:51 UTC](https://forum.confluent.io/t/multiple-event-types-in-same-topic/1634/6 "2021-05-04T08:51:10Z")

</div>

Please ignore my previous email. The plugin looks something like this. Yes, I am using a using boot app.

 ![IMG_20210504_141801](https://us1.discourse-cdn.com/flex019/uploads/confluentcommunity/original/1X/7136da5519b246827a6be00e751de0992c1ba20a.jpeg)

---

<div class="post-metadata">

**Author:** ![gpietro](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/gpietro/32/685_2.png) [@gpietro](https://forum.confluent.io/u/gpietro)\
**Post date:** [4 May 2021 09:48 UTC](https://forum.confluent.io/t/multiple-event-types-in-same-topic/1634/7 "2021-05-04T09:48:33Z")

</div>

have you tried writing the avro union **EmpTypes.avsc** like this:

```
[
"com.domain.messaging.resource.EmpCreated",
"com.domain.messaging.resource.EmpDepartmentChanged",
...
]

```

I solved by splitting the definition of the avro schemas and avro union in two different folders.

> **[spring-boot-kafka-demo/patient-location-processor/src/main at master ·...](https://github.com/gpietro/spring-boot-kafka-demo/tree/master/patient-location-processor/src/main)**
>
> master/patient-location-processor/src/main

---

<div class="post-metadata">

**Author:** ![abhisheks](https://avatars.discourse-cdn.com/v4/letter/a/85e7bf/32.png) [@abhisheks](https://forum.confluent.io/u/abhisheks)\
**Post date:** [4 May 2021 11:18 UTC](https://forum.confluent.io/t/multiple-event-types-in-same-topic/1634/8 "2021-05-04T11:18:34Z")

</div>

Tried this approach too. I still get the same error.  
Is it anything related to value.schema.id?

---

<div class="post-metadata">

**Author:** ![gpietro](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.confluent.io/gpietro/32/685_2.png) [@gpietro](https://forum.confluent.io/u/gpietro)\
**Post date:** [14 May 2021 10:10 UTC](https://forum.confluent.io/t/multiple-event-types-in-same-topic/1634/9 "2021-05-14T10:10:58Z")

</div>

Have a look at this project [GitHub - gpietro/spring-boot-kafka-demo](https://github.com/gpietro/spring-boot-kafka-demo). Here I do exactly what your are asking.

Do you register the union in the schema registry?
