From 7060cfc90abdb306ad801c97bf39beb10fdabb5a Mon Sep 17 00:00:00 2001 From: Fernando Escolar Date: Wed, 16 Oct 2024 15:48:50 +0200 Subject: [PATCH] fixing issue #1 --- Makefile | 10 ++++++ examples/bug_application_properties.js | 49 ++++++++++++++++++++++++++ sender.go | 1 + 3 files changed, 60 insertions(+) create mode 100644 examples/bug_application_properties.js diff --git a/Makefile b/Makefile index a83922b..9197856 100644 --- a/Makefile +++ b/Makefile @@ -13,4 +13,14 @@ test/run: ./k6 run examples/topic_batch_string_message.js ./k6 run examples/topic_single_message.js ./k6 run examples/topic_single_string_message.js + ./k6 run examples/bug_application_properties.js +local/compose/up: + docker compose up rabbit -d + docker compose up sbemulator -d + @export CONNECTION_STRING="Endpoint=sb://sbemulator/;SharedAccessKeyName=all;SharedAccessKey=CLwo3FQ3S39Z4pFOQDefaiUd1dSsli4XOAj3Y9Uh1E=;EnableAmqpLinkRedirect=false" + +local/compose/down: + docker compose down + +test/run/local: install compile local/compose/up test/run local/compose/down diff --git a/examples/bug_application_properties.js b/examples/bug_application_properties.js new file mode 100644 index 0000000..0663657 --- /dev/null +++ b/examples/bug_application_properties.js @@ -0,0 +1,49 @@ +import { sleep, check } from 'k6'; +import { ServiceBus } from 'k6/x/azservicebus'; +import { uuidv4 } from 'https://jslib.k6.io/k6-utils/1.4.0/index.js'; + +const config = { + connectionString: __ENV.CONNECTION_STRING, + timeout: 30000, + insecureSkipVerify: true, // the docker servicebus emulator uses a self-signed cert +}; + +const servicebus = new ServiceBus(config); +const sender = servicebus.createSender('test-topic'); +const receiver = servicebus.createSubscriptionReceiver('test-topic', 'test-sub1'); +const batch_message_count = 2; + +export default function () { + const data = []; + + for(let i = 0; i < batch_message_count; i++) { + var properties = { + 'Type': "MessageType" + }; + + data.push({ + messageID: uuidv4(), + applicationProperties: properties, + contentType: 'application/json', + subject: 'example', + bodyAsString: JSON.stringify({ Title: 'Example'}), + }); + } + + sender.sendBatchMessages(data); + + sleep(1); + + const messages = receiver.getMessages(batch_message_count); + console.log(messages); + console.log(`messages: ${messages.length}`) + check(messages, { + 'Has the expected size': (m) => m.length === batch_message_count, + }); +} + +export function teardown() { + receiver.close(); + sender.close(); + servicebus.close(); +} \ No newline at end of file diff --git a/sender.go b/sender.go index 6844276..dba4ebd 100644 --- a/sender.go +++ b/sender.go @@ -133,6 +133,7 @@ func (s *Sender) createContext() (context.Context, context.CancelFunc) { func mapMessageToSeriveBus(message *Message) *azservicebus.Message { sbMessage := &azservicebus.Message{} if message.ApplicationProperties != nil { + sbMessage.ApplicationProperties = make(map[string]any) for k, v := range message.ApplicationProperties { sbMessage.ApplicationProperties[k] = v }