@@ -40,24 +40,49 @@ connect(Config, Node) ->
4040 {{response , 3 , {open , _ , _ConnectionProperties }}, C5 } = receive_stream_commands (Sock , C4 ),
4141 {ok , Sock , C5 }.
4242
43+ close (Sock , C0 ) ->
44+ CloseReason = <<" OK" >>,
45+ CloseFrame = rabbit_stream_core :frame ({request , 1 , {close , ? RESPONSE_CODE_OK , CloseReason }}),
46+ ok = gen_tcp :send (Sock , CloseFrame ),
47+ {{response , 1 , {close , ? RESPONSE_CODE_OK }}, C1 } = receive_stream_commands (Sock , C0 ),
48+ {ok , C1 }.
49+
4350create_stream (Sock , C0 , Stream ) ->
4451 CreateStreamFrame = rabbit_stream_core :frame ({request , 1 , {create_stream , Stream , #{}}}),
4552 ok = gen_tcp :send (Sock , CreateStreamFrame ),
4653 {{response , 1 , {create_stream , ? RESPONSE_CODE_OK }}, C1 } = receive_stream_commands (Sock , C0 ),
4754 {ok , C1 }.
4855
56+ delete_stream (Sock , C0 , Stream ) ->
57+ DeleteStreamFrame = rabbit_stream_core :frame ({request , 1 , {delete_stream , Stream }}),
58+ ok = gen_tcp :send (Sock , DeleteStreamFrame ),
59+ {{response , 1 , {delete_stream , ? RESPONSE_CODE_OK }}, C1 } = receive_stream_commands (Sock , C0 ),
60+ {ok , C1 }.
61+
4962declare_publisher (Sock , C0 , Stream , PublisherId ) ->
5063 DeclarePublisherFrame = rabbit_stream_core :frame ({request , 1 , {declare_publisher , PublisherId , <<>>, Stream }}),
5164 ok = gen_tcp :send (Sock , DeclarePublisherFrame ),
5265 {{response , 1 , {declare_publisher , ? RESPONSE_CODE_OK }}, C1 } = receive_stream_commands (Sock , C0 ),
5366 {ok , C1 }.
5467
68+ delete_publisher (Sock , C0 , PublisherId ) ->
69+ DeletePublisherFrame = rabbit_stream_core :frame ({request , 1 , {delete_publisher , PublisherId }}),
70+ ok = gen_tcp :send (Sock , DeletePublisherFrame ),
71+ {{response , 1 , {delete_publisher , ? RESPONSE_CODE_OK }}, C1 } = receive_stream_commands (Sock , C0 ),
72+ {ok , C1 }.
73+
5574subscribe (Sock , C0 , Stream , SubscriptionId , InitialCredit ) ->
5675 SubscribeFrame = rabbit_stream_core :frame ({request , 1 , {subscribe , SubscriptionId , Stream , _OffsetSpec = first , InitialCredit , _Props = #{}}}),
5776 ok = gen_tcp :send (Sock , SubscribeFrame ),
5877 {{response , 1 , {subscribe , ? RESPONSE_CODE_OK }}, C1 } = receive_stream_commands (Sock , C0 ),
5978 {ok , C1 }.
6079
80+ unsubscribe (Sock , C0 , SubscriptionId ) ->
81+ UnsubscribeFrame = rabbit_stream_core :frame ({request , 1 , {unsubscribe , SubscriptionId }}),
82+ ok = gen_tcp :send (Sock , UnsubscribeFrame ),
83+ {{response , 1 , {unsubscribe , ? RESPONSE_CODE_OK }}, C1 } = receive_stream_commands (Sock , C0 ),
84+ {ok , C1 }.
85+
6186publish (Sock , C0 , PublisherId , Sequence0 , Payloads ) ->
6287 SeqIds = lists :seq (Sequence0 , Sequence0 + length (Payloads ) - 1 ),
6388 Messages = [simple_entry (Seq , P )
@@ -68,8 +93,17 @@ publish(Sock, C0, PublisherId, Sequence0, Payloads) ->
6893publish_entries (Sock , C0 , PublisherId , MsgCount , Messages ) ->
6994 PublishFrame1 = rabbit_stream_core :frame ({publish , PublisherId , MsgCount , Messages }),
7095 ok = gen_tcp :send (Sock , PublishFrame1 ),
71- {{publish_confirm , PublisherId , SeqIds }, C1 } = receive_stream_commands (Sock , C0 ),
72- {ok , SeqIds , C1 }.
96+ wait_for_confirms (Sock , C0 , PublisherId , [], MsgCount ).
97+
98+ wait_for_confirms (_ , C , _ , Acc , 0 ) ->
99+ {ok , Acc , C };
100+ wait_for_confirms (S , C0 , PublisherId , Acc , Remaining ) ->
101+ case receive_stream_commands (S , C0 ) of
102+ {{publish_confirm , PublisherId , SeqIds }, C1 } ->
103+ wait_for_confirms (S , C1 , PublisherId , Acc ++ SeqIds , Remaining - length (SeqIds ));
104+ {Frame , C1 } ->
105+ {unexpected_frame , Frame , C1 }
106+ end .
73107
74108% % Streams contain AMQP 1.0 encoded messages.
75109% % In this case, the AMQP 1.0 encoded message contains a single data section.
0 commit comments