Skip to content

Commit 7435193

Browse files
authored
Libs: add polling consumer (#1832)
This marks `v1.events-public.consumer` and `v1.events-public.consumer-seek` as _not hidden_ in the libs spec, then updates the codegen. The rust lib is currently the only one to expose this in the public API, and it is gated behind the `svix_beta` cargo feature, making it available to Bridge, etc.
2 parents 6923b47 + 0308086 commit 7435193

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1965
-5
lines changed

csharp/Svix/EventsPublic.cs

+198
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
// this file is @generated
2+
#nullable enable
3+
using Microsoft.Extensions.Logging;
4+
using Svix.Models;
5+
6+
namespace Svix
7+
{
8+
public class EventsPublicConsumerOptions : SvixOptionsBase
9+
{
10+
public ulong? Limit { get; set; }
11+
public string? Iterator { get; set; }
12+
public string? EventType { get; set; }
13+
public string? Channel { get; set; }
14+
15+
public new Dictionary<string, string> QueryParams()
16+
{
17+
return SerializeParams(
18+
new Dictionary<string, object?>
19+
{
20+
{ "limit", Limit },
21+
{ "iterator", Iterator },
22+
{ "event_type", EventType },
23+
{ "channel", Channel },
24+
}
25+
);
26+
}
27+
}
28+
29+
public class EventsPublicConsumerSeekOptions : SvixOptionsBase
30+
{
31+
public string? IdempotencyKey { get; set; }
32+
33+
public new Dictionary<string, string> HeaderParams()
34+
{
35+
return SerializeParams(
36+
new Dictionary<string, object?> { { "idempotency-key", IdempotencyKey } }
37+
);
38+
}
39+
}
40+
41+
public class EventsPublic(SvixClient client)
42+
{
43+
readonly SvixClient _client = client;
44+
45+
/// <summary>
46+
/// Reads the stream of created messages for an application, filtered on the Sink's event types and
47+
/// Channels, using server-managed iterator tracking.
48+
/// </summary>
49+
public async Task<PollingEndpointOut> ConsumerAsync(
50+
string appId,
51+
string sinkId,
52+
string consumerId,
53+
EventsPublicConsumerOptions? options = null,
54+
CancellationToken cancellationToken = default
55+
)
56+
{
57+
try
58+
{
59+
var response = await _client.SvixHttpClient.SendRequestAsync<PollingEndpointOut>(
60+
method: HttpMethod.Get,
61+
path: "/api/v1/app/{app_id}/poller/{sink_id}/consumer/{consumer_id}",
62+
pathParams: new Dictionary<string, string>
63+
{
64+
{ "app_id", appId },
65+
{ "sink_id", sinkId },
66+
{ "consumer_id", consumerId },
67+
},
68+
queryParams: options?.QueryParams(),
69+
headerParams: options?.HeaderParams(),
70+
cancellationToken: cancellationToken
71+
);
72+
return response.Data;
73+
}
74+
catch (ApiException e)
75+
{
76+
_client.Logger?.LogError(e, $"{nameof(ConsumerAsync)} failed");
77+
78+
throw;
79+
}
80+
}
81+
82+
/// <summary>
83+
/// Reads the stream of created messages for an application, filtered on the Sink's event types and
84+
/// Channels, using server-managed iterator tracking.
85+
/// </summary>
86+
public PollingEndpointOut Consumer(
87+
string appId,
88+
string sinkId,
89+
string consumerId,
90+
EventsPublicConsumerOptions? options = null
91+
)
92+
{
93+
try
94+
{
95+
var response = _client.SvixHttpClient.SendRequest<PollingEndpointOut>(
96+
method: HttpMethod.Get,
97+
path: "/api/v1/app/{app_id}/poller/{sink_id}/consumer/{consumer_id}",
98+
pathParams: new Dictionary<string, string>
99+
{
100+
{ "app_id", appId },
101+
{ "sink_id", sinkId },
102+
{ "consumer_id", consumerId },
103+
},
104+
queryParams: options?.QueryParams(),
105+
headerParams: options?.HeaderParams()
106+
);
107+
return response.Data;
108+
}
109+
catch (ApiException e)
110+
{
111+
_client.Logger?.LogError(e, $"{nameof(Consumer)} failed");
112+
113+
throw;
114+
}
115+
}
116+
117+
/// <summary>
118+
/// Sets the starting offset for the consumer of a polling endpoint.
119+
/// </summary>
120+
public async Task<PollingEndpointConsumerSeekOut> ConsumerSeekAsync(
121+
string appId,
122+
string sinkId,
123+
string consumerId,
124+
PollingEndpointConsumerSeekIn pollingEndpointConsumerSeekIn,
125+
EventsPublicConsumerSeekOptions? options = null,
126+
CancellationToken cancellationToken = default
127+
)
128+
{
129+
pollingEndpointConsumerSeekIn =
130+
pollingEndpointConsumerSeekIn
131+
?? throw new ArgumentNullException(nameof(pollingEndpointConsumerSeekIn));
132+
try
133+
{
134+
var response =
135+
await _client.SvixHttpClient.SendRequestAsync<PollingEndpointConsumerSeekOut>(
136+
method: HttpMethod.Post,
137+
path: "/api/v1/app/{app_id}/poller/{sink_id}/consumer/{consumer_id}/seek",
138+
pathParams: new Dictionary<string, string>
139+
{
140+
{ "app_id", appId },
141+
{ "sink_id", sinkId },
142+
{ "consumer_id", consumerId },
143+
},
144+
queryParams: options?.QueryParams(),
145+
headerParams: options?.HeaderParams(),
146+
content: pollingEndpointConsumerSeekIn,
147+
cancellationToken: cancellationToken
148+
);
149+
return response.Data;
150+
}
151+
catch (ApiException e)
152+
{
153+
_client.Logger?.LogError(e, $"{nameof(ConsumerSeekAsync)} failed");
154+
155+
throw;
156+
}
157+
}
158+
159+
/// <summary>
160+
/// Sets the starting offset for the consumer of a polling endpoint.
161+
/// </summary>
162+
public PollingEndpointConsumerSeekOut ConsumerSeek(
163+
string appId,
164+
string sinkId,
165+
string consumerId,
166+
PollingEndpointConsumerSeekIn pollingEndpointConsumerSeekIn,
167+
EventsPublicConsumerSeekOptions? options = null
168+
)
169+
{
170+
pollingEndpointConsumerSeekIn =
171+
pollingEndpointConsumerSeekIn
172+
?? throw new ArgumentNullException(nameof(pollingEndpointConsumerSeekIn));
173+
try
174+
{
175+
var response = _client.SvixHttpClient.SendRequest<PollingEndpointConsumerSeekOut>(
176+
method: HttpMethod.Post,
177+
path: "/api/v1/app/{app_id}/poller/{sink_id}/consumer/{consumer_id}/seek",
178+
pathParams: new Dictionary<string, string>
179+
{
180+
{ "app_id", appId },
181+
{ "sink_id", sinkId },
182+
{ "consumer_id", consumerId },
183+
},
184+
queryParams: options?.QueryParams(),
185+
headerParams: options?.HeaderParams(),
186+
content: pollingEndpointConsumerSeekIn
187+
);
188+
return response.Data;
189+
}
190+
catch (ApiException e)
191+
{
192+
_client.Logger?.LogError(e, $"{nameof(ConsumerSeek)} failed");
193+
194+
throw;
195+
}
196+
}
197+
}
198+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// this file is @generated
2+
using System.Text;
3+
using Newtonsoft.Json;
4+
5+
namespace Svix.Models
6+
{
7+
public class PollingEndpointConsumerSeekIn
8+
{
9+
[JsonProperty("after", Required = Required.Always)]
10+
public required DateTime After { get; set; }
11+
12+
public override string ToString()
13+
{
14+
StringBuilder sb = new StringBuilder();
15+
16+
sb.Append("class PollingEndpointConsumerSeekIn {\n");
17+
sb.Append(" After: ").Append(After).Append('\n');
18+
sb.Append("}\n");
19+
return sb.ToString();
20+
}
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// this file is @generated
2+
using System.Text;
3+
using Newtonsoft.Json;
4+
5+
namespace Svix.Models
6+
{
7+
public class PollingEndpointConsumerSeekOut
8+
{
9+
[JsonProperty("iterator", Required = Required.Always)]
10+
public required string Iterator { get; set; }
11+
12+
public override string ToString()
13+
{
14+
StringBuilder sb = new StringBuilder();
15+
16+
sb.Append("class PollingEndpointConsumerSeekOut {\n");
17+
sb.Append(" Iterator: ").Append(Iterator).Append('\n');
18+
sb.Append("}\n");
19+
return sb.ToString();
20+
}
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// this file is @generated
2+
using System.Text;
3+
using Newtonsoft.Json;
4+
5+
namespace Svix.Models
6+
{
7+
/// <summary>
8+
/// The MessageOut equivalent of polling endpoint
9+
/// <summary>
10+
11+
public class PollingEndpointMessageOut
12+
{
13+
[JsonProperty("channels")]
14+
public List<string>? Channels { get; set; } = null;
15+
16+
[JsonProperty("eventId")]
17+
public string? EventId { get; set; } = null;
18+
19+
[JsonProperty("eventType", Required = Required.Always)]
20+
public required string EventType { get; set; }
21+
22+
[JsonProperty("headers")]
23+
public Dictionary<string, string>? Headers { get; set; } = null;
24+
25+
[JsonProperty("id", Required = Required.Always)]
26+
public required string Id { get; set; }
27+
28+
[JsonProperty("payload", Required = Required.Always)]
29+
public required Object Payload { get; set; }
30+
31+
[JsonProperty("tags")]
32+
public List<string>? Tags { get; set; } = null;
33+
34+
[JsonProperty("timestamp", Required = Required.Always)]
35+
public required DateTime Timestamp { get; set; }
36+
37+
public override string ToString()
38+
{
39+
StringBuilder sb = new StringBuilder();
40+
41+
sb.Append("class PollingEndpointMessageOut {\n");
42+
sb.Append(" Channels: ").Append(Channels).Append('\n');
43+
sb.Append(" EventId: ").Append(EventId).Append('\n');
44+
sb.Append(" EventType: ").Append(EventType).Append('\n');
45+
sb.Append(" Headers: ").Append(Headers).Append('\n');
46+
sb.Append(" Id: ").Append(Id).Append('\n');
47+
sb.Append(" Payload: ").Append(Payload).Append('\n');
48+
sb.Append(" Tags: ").Append(Tags).Append('\n');
49+
sb.Append(" Timestamp: ").Append(Timestamp).Append('\n');
50+
sb.Append("}\n");
51+
return sb.ToString();
52+
}
53+
}
54+
}
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// this file is @generated
2+
using System.Text;
3+
using Newtonsoft.Json;
4+
5+
namespace Svix.Models
6+
{
7+
public class PollingEndpointOut
8+
{
9+
[JsonProperty("data", Required = Required.Always)]
10+
public required List<PollingEndpointMessageOut> Data { get; set; }
11+
12+
[JsonProperty("done", Required = Required.Always)]
13+
public required bool Done { get; set; }
14+
15+
[JsonProperty("iterator", Required = Required.Always)]
16+
public required string Iterator { get; set; }
17+
18+
public override string ToString()
19+
{
20+
StringBuilder sb = new StringBuilder();
21+
22+
sb.Append("class PollingEndpointOut {\n");
23+
sb.Append(" Data: ").Append(Data).Append('\n');
24+
sb.Append(" Done: ").Append(Done).Append('\n');
25+
sb.Append(" Iterator: ").Append(Iterator).Append('\n');
26+
sb.Append("}\n");
27+
return sb.ToString();
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)