-
Notifications
You must be signed in to change notification settings - Fork 67
Add support for AUTO_PRODUCE schema #572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[source,java,subs="attributes,verbatim"] | ||
---- | ||
void sendUserAsBytes(PulsarTemplate<byte[]> template, byte[] userAsBytes) { | ||
template.send("user-topic", userAsBytes, Schema.AUTO_PRODUCE_BYTES()); | ||
} | ||
---- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[source,java,subs="attributes,verbatim"] | ||
---- | ||
void sendUserAsBytes(ReactivePulsarTemplate<byte[]> template, byte[] userAsBytes) { | ||
template.send("user-topic", userAsBytes, Schema.AUTO_PRODUCE_BYTES()).subscribe(); | ||
} | ||
---- |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,9 @@ | |
import org.apache.pulsar.client.api.Schema; | ||
import org.apache.pulsar.client.api.TypedMessageBuilder; | ||
import org.apache.pulsar.client.api.transaction.Transaction; | ||
import org.apache.pulsar.client.impl.schema.AutoProduceBytesSchema; | ||
import org.apache.pulsar.common.protocol.schema.SchemaHash; | ||
import org.apache.pulsar.common.schema.SchemaType; | ||
|
||
import org.springframework.beans.factory.DisposableBean; | ||
import org.springframework.core.log.LogAccessor; | ||
|
@@ -168,6 +170,8 @@ private void closeProducer(Producer<T> producer, boolean async) { | |
*/ | ||
static class ProducerCacheKey<T> { | ||
|
||
private static final SchemaHash AUTO_PRODUCE_SCHEMA_HASH = SchemaHash.of(new byte[0], SchemaType.AUTO_PUBLISH); | ||
|
||
private final Schema<T> schema; | ||
|
||
private final SchemaHash schemaHash; | ||
|
@@ -193,7 +197,8 @@ static class ProducerCacheKey<T> { | |
Assert.notNull(schema, () -> "'schema' must be non-null"); | ||
Assert.notNull(topic, () -> "'topic' must be non-null"); | ||
this.schema = schema; | ||
this.schemaHash = SchemaHash.of(this.schema); | ||
this.schemaHash = (schema instanceof AutoProduceBytesSchema) ? AUTO_PRODUCE_SCHEMA_HASH | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is necessary as any call to |
||
: SchemaHash.of(this.schema); | ||
this.topic = topic; | ||
this.encryptionKeys = encryptionKeys; | ||
this.customizers = customizers; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2022-2023 the original author or authors. | ||
* Copyright 2022-2024 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -49,6 +49,7 @@ | |
import org.springframework.pulsar.cache.provider.CacheProvider; | ||
import org.springframework.pulsar.core.CachingPulsarProducerFactory.ProducerCacheKey; | ||
import org.springframework.pulsar.core.CachingPulsarProducerFactory.ProducerWithCloseCallback; | ||
import org.springframework.pulsar.test.support.model.UserPojo; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
import org.springframework.util.ObjectUtils; | ||
|
||
|
@@ -74,7 +75,7 @@ void cleanupFromTests() { | |
} | ||
|
||
@Test | ||
void createProducerMultipleCalls() throws PulsarClientException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [UNRELATED] Leftover from removal of checked exception in Spring Pulsar APIs. |
||
void createProducerMultipleCalls() { | ||
var producerFactory = newProducerFactory(); | ||
var cacheKey = new ProducerCacheKey<>(schema, "topic1", null, null); | ||
var producer1 = producerFactory.createProducer(schema, "topic1"); | ||
|
@@ -103,7 +104,7 @@ void cachedProducerIsCloseSafeWrapper() throws PulsarClientException { | |
|
||
@SuppressWarnings("resource") | ||
@Test | ||
void createProducerWithMatrixOfCacheKeys() throws PulsarClientException { | ||
void createProducerWithMatrixOfCacheKeys() { | ||
String topic1 = "topic1"; | ||
String topic2 = "topic2"; | ||
var schema1 = new StringSchema(); | ||
|
@@ -167,7 +168,7 @@ void createProducerWithMatrixOfCacheKeys() throws PulsarClientException { | |
} | ||
|
||
@Test | ||
void factoryDestroyCleansUpCacheAndClosesProducers() throws PulsarClientException { | ||
void factoryDestroyCleansUpCacheAndClosesProducers() { | ||
CachingPulsarProducerFactory<String> producerFactory = producerFactory(pulsarClient, null, null); | ||
var actualProducer1 = actualProducer(producerFactory.createProducer(schema, "topic1")); | ||
var actualProducer2 = actualProducer(producerFactory.createProducer(schema, "topic2")); | ||
|
@@ -183,7 +184,7 @@ void factoryDestroyCleansUpCacheAndClosesProducers() throws PulsarClientExceptio | |
} | ||
|
||
@Test | ||
void producerEvictedFromCache() throws PulsarClientException { | ||
void producerEvictedFromCache() { | ||
CachingPulsarProducerFactory<String> producerFactory = new CachingPulsarProducerFactory<>(pulsarClient, null, | ||
null, new DefaultTopicResolver(), Duration.ofSeconds(3L), 10L, 2); | ||
var actualProducer = actualProducer(producerFactory.createProducer(schema, "topic1")); | ||
|
@@ -306,7 +307,21 @@ static Stream<Arguments> equalsAndHashCodeTestProvider() { | |
arguments( | ||
Named.of("differentNullInterceptor", | ||
new ProducerCacheKey<>(Schema.STRING, "topic1", encryptionKeys1, customizers1)), | ||
new ProducerCacheKey<>(Schema.STRING, "topic1", null, null), false)); | ||
new ProducerCacheKey<>(Schema.STRING, "topic1", null, null), false), | ||
arguments( | ||
Named.of("sameAutoProduceSchemaSameTopic", | ||
new ProducerCacheKey<>(Schema.AUTO_PRODUCE_BYTES(), "topic1", null, null)), | ||
new ProducerCacheKey<>(Schema.AUTO_PRODUCE_BYTES(), "topic1", null, null), true), | ||
arguments( | ||
Named.of("autoProduceSchemaOneWithAndOneWithoutSchemaInfo", | ||
new ProducerCacheKey<>(Schema.AUTO_PRODUCE_BYTES(), "topic1", null, null)), | ||
new ProducerCacheKey<>(Schema.AUTO_PRODUCE_BYTES(Schema.AVRO(UserPojo.class)), "topic1", | ||
null, null), | ||
true), | ||
arguments( | ||
Named.of("sameAutoProduceSchemaDifferentTopic", | ||
new ProducerCacheKey<>(Schema.AUTO_PRODUCE_BYTES(), "topic1", null, null)), | ||
new ProducerCacheKey<>(Schema.AUTO_PRODUCE_BYTES(), "topic2", null, null), false)); | ||
} | ||
|
||
} | ||
|
@@ -315,7 +330,7 @@ static Stream<Arguments> equalsAndHashCodeTestProvider() { | |
class RestartFactoryTests { | ||
|
||
@Test | ||
void restartLifecycle() throws PulsarClientException { | ||
void restartLifecycle() { | ||
var producerFactory = (CachingPulsarProducerFactory<String>) producerFactory(pulsarClient, null, null); | ||
producerFactory.start(); | ||
var producer1 = producerFactory.createProducer(schema, "topic1"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[UNRELATED] Bump in docs to current version