Hello
In the StreamBridge class, the method getStreamBridgeFunction uses the method hashProducerProperties to get the key in the cache.
Here's my configuration :
one topic with 2 partitions one with partition-key-expression and one without partition-key-expression
spring:
cloud:
stream:
bindings:
binding1:
producer:
partitionCount: 2
content-type: application/json
destination: topic1
binding2:
producer:
partition-key-expression: headers['partitionKey']
partitionCount: 8
content-type: application/json
destination: topic2
Because the difference of hash of Boolean.hashcode(boolean value) is 6.
public static int hashCode(boolean value) {
return value ? 1231 : 1237;
}
The hash for binding1 will be
outputContentType.hashCode() --> X
- Boolean.hashCode(producerProperties.isUseNativeEncoding()) --> Y
- Boolean.hashCode(producerProperties.isPartitioned()) --> 1237
- producerProperties.getPartitionCount(); --> 2
The hash for binding 2 will be
outputContentType.hashCode() --> X
- Boolean.hashCode(producerProperties.isUseNativeEncoding()) --> Y
- Boolean.hashCode(producerProperties.isPartitioned()) --> 1231
- producerProperties.getPartitionCount(); --> 8
So hash for binding1 = hash for binding2 = X + Y + 1239
The cache will return the same function, I have an error on binding1 because I don't provide the header "partition-key" if the first one used (and put in cache) is binding2
Thanks
Hello
In the StreamBridge class, the method getStreamBridgeFunction uses the method hashProducerProperties to get the key in the cache.
Here's my configuration :
one topic with 2 partitions one with partition-key-expression and one without partition-key-expression
Because the difference of hash of Boolean.hashcode(boolean value) is 6.
The hash for binding1 will be
outputContentType.hashCode() --> X
The hash for binding 2 will be
outputContentType.hashCode() --> X
So hash for binding1 = hash for binding2 = X + Y + 1239
The cache will return the same function, I have an error on binding1 because I don't provide the header "partition-key" if the first one used (and put in cache) is binding2
Thanks