diff --git a/client.go b/client.go index 40dd72b5..ce132db7 100644 --- a/client.go +++ b/client.go @@ -1506,7 +1506,7 @@ func LinkReceiverSettle(mode ReceiverSettleMode) LinkOption { // LinkSessionFilter sets a session filter (com.microsoft:session-filter) on the link source. // This is used in Azure Service Bus to filter messages by session ID on a receiving link. -func LinkSessionFilter(sessionID string) LinkOption { +func LinkSessionFilter(sessionID *string) LinkOption { // return linkSourceFilter("com.microsoft:session-filter", uint64(0x00000137000000C), sessionID) } @@ -1514,11 +1514,11 @@ func LinkSessionFilter(sessionID string) LinkOption { // LinkSelectorFilter sets a selector filter (apache.org:selector-filter:string) on the link source. func LinkSelectorFilter(filter string) LinkOption { // - return linkSourceFilter("apache.org:selector-filter:string", uint64(0x0000468C00000004), filter) + return linkSourceFilter("apache.org:selector-filter:string", uint64(0x0000468C00000004), &filter) } // linkSourceFilter sets a filter on the link source. -func linkSourceFilter(name string, code uint64, value string) LinkOption { +func linkSourceFilter(name string, code uint64, value *string) LinkOption { nameSym := symbol(name) return func(l *link) error { if l.source == nil { @@ -1527,10 +1527,18 @@ func linkSourceFilter(name string, code uint64, value string) LinkOption { if l.source.Filter == nil { l.source.Filter = make(map[symbol]*describedType) } - l.source.Filter[nameSym] = &describedType{ + + describedValue := &describedType{ descriptor: code, - value: value, } + + if value == nil { + describedValue.value = nil + } else { + describedValue.value = *value + } + + l.source.Filter[nameSym] = describedValue return nil } } diff --git a/client_test.go b/client_test.go index 86efeeb0..9af45b54 100644 --- a/client_test.go +++ b/client_test.go @@ -6,6 +6,8 @@ import ( ) func TestLinkOptions(t *testing.T) { + sessionID := "123" + tests := []struct { label string opts []LinkOption @@ -24,7 +26,7 @@ func TestLinkOptions(t *testing.T) { LinkProperty("x-opt-test2", "test2"), LinkProperty("x-opt-test1", "test3"), LinkPropertyInt64("x-opt-test4", 1), - LinkSessionFilter("123"), + LinkSessionFilter(&sessionID), }, wantSource: &source{ @@ -35,7 +37,7 @@ func TestLinkOptions(t *testing.T) { }, "com.microsoft:session-filter" : { descriptor: binary.BigEndian.Uint64([]byte{0x00, 0x00, 0x00, 0x13, 0x70, 0x00, 0x00, 0x0C}), - value: "123", + value: sessionID, }, }, }, @@ -45,6 +47,21 @@ func TestLinkOptions(t *testing.T) { "x-opt-test4": int64(1), }, }, + { + label: "more-link-filters", + opts: []LinkOption{ + LinkSessionFilter(nil), + }, + + wantSource: &source{ + Filter: map[symbol]*describedType{ + "com.microsoft:session-filter" : { + descriptor: binary.BigEndian.Uint64([]byte{0x00, 0x00, 0x00, 0x13, 0x70, 0x00, 0x00, 0x0C}), + value: nil, + }, + }, + }, + }, } for _, tt := range tests {