Skip to content

Commit 6d9e9b9

Browse files
Merge pull request #9813 from rabbitmq/super-stream-frames
Add super stream creation/deletion commands
2 parents 2adec32 + 5e1155c commit 6d9e9b9

File tree

10 files changed

+436
-93
lines changed

10 files changed

+436
-93
lines changed

deps/rabbitmq_stream/docs/PROTOCOL.adoc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,16 @@ used to make the difference between a request (0) and a response (1). Example fo
230230
|0x001c
231231
|Yes
232232

233+
|<<createsuperstream>>
234+
|Client
235+
|0x001d
236+
|Yes
237+
238+
|<<deletesuperstream>>
239+
|Client
240+
|0x001e
241+
|Yes
242+
233243
|===
234244

235245
=== DeclarePublisher
@@ -754,6 +764,31 @@ StreamStatsResponse => Key Version CorrelationId ResponseCode Stats
754764
Value => int64
755765
```
756766

767+
=== CreateSuperStream
768+
769+
```
770+
CreateSuperStream => Key Version CorrelationId Name [Partition] [BindingKey] Arguments
771+
Key => uint16 // 0x001d
772+
Version => uint16
773+
CorrelationId => uint32
774+
Name => string
775+
Partition => string
776+
BindingKey => string
777+
Arguments => [Argument]
778+
Argument => Key Value
779+
Key => string
780+
Value => string
781+
```
782+
783+
=== DeleteSuperStream
784+
785+
```
786+
Delete => Key Version CorrelationId Name
787+
Key => uint16 // 0x001e
788+
Version => uint16
789+
CorrelationId => uint32
790+
Name => string
791+
```
757792

758793
== Authentication
759794

deps/rabbitmq_stream/src/rabbit_stream_manager.erl

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ create_super_stream(VirtualHost,
7373
Name,
7474
Partitions,
7575
Arguments,
76-
RoutingKeys,
76+
BindingKeys,
7777
Username) ->
7878
gen_server:call(?MODULE,
7979
{create_super_stream,
8080
VirtualHost,
8181
Name,
8282
Partitions,
8383
Arguments,
84-
RoutingKeys,
84+
BindingKeys,
8585
Username}).
8686

8787
-spec delete_super_stream(binary(), binary(), binary()) ->
@@ -226,10 +226,10 @@ handle_call({create_super_stream,
226226
Name,
227227
Partitions,
228228
Arguments,
229-
RoutingKeys,
229+
BindingKeys,
230230
Username},
231231
_From, State) ->
232-
case validate_super_stream_creation(VirtualHost, Name, Partitions) of
232+
case validate_super_stream_creation(VirtualHost, Name, Partitions, BindingKeys) of
233233
{error, Reason} ->
234234
{reply, {error, Reason}, State};
235235
ok ->
@@ -273,7 +273,7 @@ handle_call({create_super_stream,
273273
add_super_stream_bindings(VirtualHost,
274274
Name,
275275
Partitions,
276-
RoutingKeys,
276+
BindingKeys,
277277
Username),
278278
case BindingsResult of
279279
ok ->
@@ -445,8 +445,8 @@ handle_call({route, RoutingKey, VirtualHost, SuperStream}, _From,
445445
end
446446
catch
447447
exit:Error ->
448-
rabbit_log:error("Error while looking up exchange ~tp, ~tp",
449-
[rabbit_misc:rs(ExchangeName), Error]),
448+
rabbit_log:warning("Error while looking up exchange ~tp, ~tp",
449+
[rabbit_misc:rs(ExchangeName), Error]),
450450
{error, stream_not_found}
451451
end,
452452
{reply, Res, State};
@@ -655,7 +655,10 @@ super_stream_partitions(VirtualHost, SuperStream) ->
655655
{error, stream_not_found}
656656
end.
657657

658-
validate_super_stream_creation(VirtualHost, Name, Partitions) ->
658+
validate_super_stream_creation(_VirtualHost, _Name, Partitions, BindingKeys)
659+
when length(Partitions) =/= length(BindingKeys) ->
660+
{error, {validation_failed, "There must be the same number of partitions and binding keys"}};
661+
validate_super_stream_creation(VirtualHost, Name, Partitions, _BindingKeys) ->
659662
case exchange_exists(VirtualHost, Name) of
660663
{error, validation_failed} ->
661664
{error,
@@ -758,15 +761,15 @@ declare_super_stream_exchange(VirtualHost, Name, Username) ->
758761
add_super_stream_bindings(VirtualHost,
759762
Name,
760763
Partitions,
761-
RoutingKeys,
764+
BindingKeys,
762765
Username) ->
763-
PartitionsRoutingKeys = lists:zip(Partitions, RoutingKeys),
766+
PartitionsBindingKeys = lists:zip(Partitions, BindingKeys),
764767
BindingsResult =
765-
lists:foldl(fun ({Partition, RoutingKey}, {ok, Order}) ->
768+
lists:foldl(fun ({Partition, BindingKey}, {ok, Order}) ->
766769
case add_super_stream_binding(VirtualHost,
767770
Name,
768771
Partition,
769-
RoutingKey,
772+
BindingKey,
770773
Order,
771774
Username)
772775
of
@@ -778,7 +781,7 @@ add_super_stream_bindings(VirtualHost,
778781
(_, {{error, _Reason}, _Order} = Acc) ->
779782
Acc
780783
end,
781-
{ok, 0}, PartitionsRoutingKeys),
784+
{ok, 0}, PartitionsBindingKeys),
782785
case BindingsResult of
783786
{ok, _} ->
784787
ok;
@@ -789,7 +792,7 @@ add_super_stream_bindings(VirtualHost,
789792
add_super_stream_binding(VirtualHost,
790793
SuperStream,
791794
Partition,
792-
RoutingKey,
795+
BindingKey,
793796
Order,
794797
Username) ->
795798
{ok, ExchangeNameBin} =
@@ -806,7 +809,7 @@ add_super_stream_binding(VirtualHost,
806809
Order),
807810
case rabbit_binding:add(#binding{source = ExchangeName,
808811
destination = QueueName,
809-
key = RoutingKey,
812+
key = BindingKey,
810813
args = Arguments},
811814
fun (_X, Q) when ?is_amqqueue(Q) ->
812815
try

0 commit comments

Comments
 (0)