You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-pulsar-docs/src/main/antora/modules/ROOT/pages/reference/schema-info/custom-schema-mapping.adoc
+17
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,4 @@
1
+
==== Configuration properties
1
2
Schema mappings can be configured with the `spring.pulsar.defaults.type-mappings` property.
2
3
The following example uses `application.yml` to add mappings for the `User` and `Address` complex objects using `AVRO` and `JSON` schemas, respectively:
3
4
@@ -17,6 +18,7 @@ spring:
17
18
18
19
NOTE: The `message-type` is the fully-qualified name of the message class.
19
20
21
+
==== Schema resolver customizer
20
22
The preferred method of adding mappings is via the property mentioned above.
21
23
However, if more control is needed you can provide a schema resolver customizer to add the mapping(s).
22
24
@@ -32,3 +34,18 @@ public SchemaResolverCustomizer<DefaultSchemaResolver> schemaResolverCustomizer(
32
34
}
33
35
}
34
36
----
37
+
38
+
==== Type mapping annotation
39
+
Another option for specifying default schema information to use for a particular message type is to mark the message class with the `@PulsarTypeMapping` annotation.
40
+
The schema info can be specified via the `schemaType` attribute on the annotation.
41
+
42
+
The following example configures the system to use JSON as the default schema when producing or consuming messages of type `Foo`:
43
+
44
+
[source,java,indent=0,subs="verbatim"]
45
+
----
46
+
@PulsarTypeMapping(schemaType = SchemaType.JSON)
47
+
record Foo(String value) {
48
+
}
49
+
----
50
+
51
+
NOTE: The annotations are looked up on-demand and their result is cached. However, there is still a small performance hit on the first lookup. If you want to disable this feature you can invoke the `usePulsarTypeMappingAnnotations(false)` method on the `DefaultSchemaResolver`.
Copy file name to clipboardExpand all lines: spring-pulsar-docs/src/main/antora/modules/ROOT/pages/reference/topic-resolution.adoc
+9-3
Original file line number
Diff line number
Diff line change
@@ -35,15 +35,21 @@ NOTE: The `message-type` is the fully-qualified name of the message class.
35
35
WARNING: If the message (or the first message of a `Publisher` input) is `null`, the framework won't be able to determine the topic from it. Another method shall be used to specify the topic if your application is likely to send `null` messages.
36
36
37
37
=== Specified via annotation
38
-
When no topic passed into API and no mappings configured, the system looks for `PulsarTopic` annotation. The following example configures topic for `Baz` class using annotation:
38
+
39
+
When no topic is passed into the API and there are no custom topic mappings configured, the system looks for a `@PulsarTypeMapping` annotation on the class of the message being produced or consumed.
40
+
The default topic can be specified via the `topic` attribute on the annotation.
41
+
42
+
The following example configures the default topic to use when producing or consuming messages of type `Foo`:
39
43
40
44
[source,java,indent=0,subs="verbatim"]
41
45
----
42
-
@PulsarTopic("baz-topic")
43
-
record Baz(String value) {
46
+
@PulsarTypeMapping(topic = "foo-topic")
47
+
record Foo(String value) {
44
48
}
45
49
----
46
50
51
+
NOTE: The annotations are looked up on-demand and their result is cached. However, there is still a small performance hit on the first lookup. If you want to disable this feature you can invoke the `usePulsarTypeMappingAnnotations(false)` method on the `DefaultTopicResolver`.
52
+
47
53
=== Custom topic resolver
48
54
The preferred method of adding mappings is via the property mentioned above.
49
55
However, if more control is needed you can replace the default resolver by proving your own implementation, for example:
0 commit comments