diff --git a/primitive/message.go b/primitive/message.go index 32adc2b6..f206cb51 100644 --- a/primitive/message.go +++ b/primitive/message.go @@ -182,13 +182,7 @@ func (m *Message) WithTag(tags string) *Message { } func (m *Message) WithKeys(keys []string) *Message { - var sb strings.Builder - for _, k := range keys { - sb.WriteString(k) - sb.WriteString(PropertyKeySeparator) - } - - m.WithProperty(PropertyKeys, sb.String()) + m.WithProperty(PropertyKeys, strings.Join(keys, PropertyKeySeparator)) return m } diff --git a/primitive/message_test.go b/primitive/message_test.go index e47a2981..7248df7a 100644 --- a/primitive/message_test.go +++ b/primitive/message_test.go @@ -36,3 +36,13 @@ func TestMessageID(t *testing.T) { } t.Log(msgID) } + +func TestMessageKey(t *testing.T) { + msg := &Message{} + expected := "testKey" + msg.WithKeys([]string{expected}) + actual := msg.GetKeys() + if actual != expected { + t.Fatalf("get message key error: expected is '%s', actual is '%s'", expected, actual) + } +}