shibd commented on code in PR #433:
URL:
https://github.com/apache/pulsar-client-node/pull/433#discussion_r2381290557
##########
tests/producer.test.js:
##########
@@ -156,5 +159,95 @@ const Pulsar = require('../index');
await producer2.close();
});
});
+ describe('Message Routing', () => {
+ test('Custom Message Router', async () => {
+ // 1. Define a partitioned topic and a custom router
+ const targetPartition = 1;
+ const partitionedTopicName = `test-custom-router-${Date.now()}`;
+ const partitionedTopic =
`persistent://public/default/${partitionedTopicName}`;
+ const numPartitions = 10;
+
+ // Use admin client to create a partitioned topic. This is more robust.
+ // Assuming 'adminUrl' and 'httpRequest' are available from your test
setup.
+ const partitionedTopicAdminURL =
`${adminUrl}/admin/v2/persistent/public/default/${partitionedTopicName}/partitions`;
+ const createPartitionedTopicRes = await httpRequest(
+ partitionedTopicAdminURL, {
+ headers: {
+ 'Content-Type': 'application/json', // Use application/json for
REST API
+ },
+ data: numPartitions,
+ method: 'PUT',
+ },
+ );
+ // 204 No Content is success for PUT create
+ expect(createPartitionedTopicRes.statusCode).toBe(204);
+
+ // 2. Create a producer with the custom message router
+ const producer = await client.createProducer({
+ topic: partitionedTopic, // Note: For producer, use the base topic
name
+ messageRouter: (message, topicMetadata) => targetPartition,
Review Comment:
Good point, I implemented a simple hash method and use message and
topicMetadata.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]