-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for super stream key routing (#270)
* Add support for super stream key routing --------- Signed-off-by: Gabriele Santomaggio <[email protected]>
- Loading branch information
1 parent
0f5cd64
commit cdbbfc5
Showing
12 changed files
with
533 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// This source code is dual-licensed under the Apache License, version | ||
// 2.0, and the Mozilla Public License, version 2.0. | ||
// Copyright (c) 2007-2023 VMware, Inc. | ||
|
||
using System; | ||
|
||
namespace RabbitMQ.Stream.Client; | ||
|
||
internal readonly struct RouteQueryRequest : ICommand | ||
{ | ||
public const ushort Key = 0x0018; | ||
private readonly string _superStream; | ||
private readonly string _routingKey; | ||
private readonly uint _corrId; | ||
|
||
public RouteQueryRequest(uint corrId, string superStream, string routingKey) | ||
{ | ||
_corrId = corrId; | ||
_superStream = superStream; | ||
_routingKey = routingKey; | ||
} | ||
|
||
public int SizeNeeded => 2 + 2 + 4 + | ||
WireFormatting.StringSize(_superStream) + | ||
WireFormatting.StringSize(_routingKey); | ||
|
||
public int Write(Span<byte> span) | ||
{ | ||
var command = (ICommand)this; | ||
var offset = WireFormatting.WriteUInt16(span, Key); | ||
offset += WireFormatting.WriteUInt16(span[offset..], command.Version); | ||
offset += WireFormatting.WriteUInt32(span[offset..], _corrId); | ||
offset += WireFormatting.WriteString(span[offset..], _routingKey); | ||
offset += WireFormatting.WriteString(span[offset..], _superStream); | ||
return offset; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// This source code is dual-licensed under the Apache License, version | ||
// 2.0, and the Mozilla Public License, version 2.0. | ||
// Copyright (c) 2007-2023 VMware, Inc. | ||
|
||
using System; | ||
using System.Buffers; | ||
using System.Collections.Generic; | ||
|
||
namespace RabbitMQ.Stream.Client; | ||
|
||
public struct RouteQueryResponse : ICommand | ||
{ | ||
public const ushort Key = 0x0018; | ||
|
||
public RouteQueryResponse(uint correlationId, ResponseCode responseCode, List<string> streams) | ||
{ | ||
Streams = streams; | ||
ResponseCode = responseCode; | ||
CorrelationId = correlationId; | ||
} | ||
|
||
public List<string> Streams { get; } | ||
public int SizeNeeded => throw new NotImplementedException(); | ||
public int Write(Span<byte> span) => throw new NotImplementedException(); | ||
|
||
public uint CorrelationId { get; } | ||
public ResponseCode ResponseCode { get; } | ||
|
||
internal static int Read(ReadOnlySequence<byte> frame, out RouteQueryResponse command) | ||
{ | ||
var offset = WireFormatting.ReadUInt16(frame, out _); | ||
offset += WireFormatting.ReadUInt16(frame.Slice(offset), out _); | ||
offset += WireFormatting.ReadUInt32(frame.Slice(offset), out var correlationId); | ||
offset += WireFormatting.ReadUInt16(frame.Slice(offset), out var responseCode); | ||
offset += WireFormatting.ReadUInt32(frame.Slice(offset), out var numOfStreams); | ||
|
||
var streams = new List<string>(); | ||
for (var i = 0; i < numOfStreams; i++) | ||
{ | ||
offset += WireFormatting.ReadString(frame.Slice(offset), out var stream); | ||
streams.Add(stream); | ||
} | ||
|
||
command = new RouteQueryResponse(correlationId, (ResponseCode)responseCode, streams); | ||
return offset; | ||
} | ||
} |
Oops, something went wrong.