Skip to content

Commit 5ec3bc1

Browse files
dev: update serverless example && Ydb.Sdk.Services.Topic moved to Ydb.Sdk.Topic (#539)
* dev: update serverless example * **Breaking Change**: `Ydb.Sdk.Services.Topic` moved to `Ydb.Sdk.Topic`.
1 parent b63680c commit 5ec3bc1

32 files changed

+67
-62
lines changed

examples/Ydb.Sdk.AdoNet.Yandex.Cloud.Serverless.Container/Program.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Diagnostics;
2+
using Dapper;
23
using Microsoft.Extensions.Configuration;
34
using Microsoft.Extensions.Logging;
45
using NLog.Extensions.Logging;
@@ -18,18 +19,17 @@
1819
var stopwatch = Stopwatch.StartNew();
1920
stopwatch.Start();
2021

21-
await using var dataSource = new YdbDataSource(
22-
new YdbConnectionStringBuilder(connectionString)
23-
{
24-
CredentialsProvider = new MetadataProvider(loggerFactory: loggerFactory),
25-
LoggerFactory = loggerFactory,
26-
DisableDiscovery = true
27-
}
28-
);
22+
await using var ydbDataSource = new YdbDataSource(new YdbConnectionStringBuilder(connectionString)
23+
{
24+
CredentialsProvider = new MetadataProvider(loggerFactory: loggerFactory),
25+
LoggerFactory = loggerFactory,
26+
DisableDiscovery = true,
27+
EnableImplicitSession = true
28+
});
2929

30-
await using var ydbCommand = dataSource.CreateCommand();
31-
ydbCommand.CommandText = "SELECT 'Hello Serverless YDB from Yandex Cloud Serverless Container!'u";
32-
var scalar = await ydbCommand.ExecuteScalarAsync();
30+
await using var ydbConnection = await ydbDataSource.OpenRetryableConnectionAsync();
31+
var scalar = await ydbConnection.ExecuteScalarAsync<string>(
32+
"SELECT 'Hello Serverless YDB from Yandex Cloud Serverless Container!'u");
3333
stopwatch.Stop();
3434

3535
logger.LogInformation("Success request! [Ms: {Ms}], {Select}", stopwatch.ElapsedMilliseconds, scalar);

examples/Ydb.Sdk.AdoNet.Yandex.Cloud.Serverless.Container/README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,32 @@ to [Yandex Cloud Serverless Containers](https://yandex.cloud/en/docs/serverless-
66
## Getting started
77

88
1. **Setup** [Yandex Container Registry](https://yandex.cloud/en/docs/container-registry/operations/registry/registry-create).
9-
2. **Build and Push Docker Image**
9+
2. **Configure YDB Connection String**. Update the `appsettings.json` file with your YDB connection details:
10+
```json
11+
{
12+
"ConnectionStrings": {
13+
"ServerlessYDB": "UseTls=true;Host=<your-ydb-host>;Port=2135;Database=<your-database-path>"
14+
}
15+
}
16+
```
17+
Replace `<your-ydb-host>` with your YDB endpoint host and `<your-database-path>` with your database path (e.g., `/ru-central1/b1g8ejbxxxxxxxx/etn8xxxxxxxx`).
18+
3. **Build and Push Docker Image**
1019
```bash
1120
docker build . -t cr.yandex/<container-registry-id>/ado-net-app:latest
1221
docker push cr.yandex/<container-registry-id>/ado-net-app:latest
1322
```
1423
Replace <container-registry-id> with your actual Container Registry ID.
15-
3. **Grant Required Permissions**. To enable your Serverless Container to access both YDB and your container image in
24+
4. **Grant Required Permissions**. To enable your Serverless Container to access both YDB and your container image in
1625
the Container Registry, grant the following roles to your Service Account:
1726

1827
- `ydb.editor` — access to YDB,
1928
- `container-registry.images.puller` — permission to pull images from Container Registry.
2029

21-
4. **Create a new revision**. After pushing your image, create a new version of the Serverless Container as described in
30+
5. **Create a new revision**. After pushing your image, create a new version of the Serverless Container as described in
2231
the [official guide](https://yandex.cloud/en/docs/serverless-containers/quickstart/container#create-revision).
2332
Specify your image and the necessary environment variables and secrets.
2433

25-
5. **Running the Yandex Serverless Container**.
34+
6. **Running the Yandex Serverless Container**.
2635
After the new revision has been rolled out, you can use your container (e.g., for a health check) by executing the
2736
following command:
2837
```bash

examples/Ydb.Sdk.AdoNet.Yandex.Cloud.Serverless.Container/Ydb.Sdk.AdoNet.Yandex.Cloud.Serverless.Container.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0"/>
1616
<PackageReference Include="NLog.Extensions.Logging" Version="5.5.0"/>
1717
<PackageReference Include="Ydb.Sdk.Yc.Auth" Version="0.2.0"/>
18-
<PackageReference Include="Ydb.Sdk" Version="0.18.0"/>
18+
<PackageReference Include="Ydb.Sdk" Version="0.24.0"/>
19+
<PackageReference Include="Dapper" Version="2.1.35"/>
1920

2021
<None Update="appsettings.json">
2122
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>

examples/Ydb.Sdk.Topic.QuickStart/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using Microsoft.Extensions.Logging;
22
using Ydb.Sdk;
3-
using Ydb.Sdk.Services.Topic;
4-
using Ydb.Sdk.Services.Topic.Reader;
5-
using Ydb.Sdk.Services.Topic.Writer;
3+
using Ydb.Sdk.Topic;
4+
using Ydb.Sdk.Topic.Reader;
5+
using Ydb.Sdk.Topic.Writer;
66

77
const int countMessages = 100;
88
const string topicName = "topic_name";

slo/src/TopicService/SloTopicContext.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
using Microsoft.Extensions.Logging;
55
using Ydb.Sdk;
66
using Ydb.Sdk.Ado;
7-
using Ydb.Sdk.Services.Topic;
8-
using Ydb.Sdk.Services.Topic.Reader;
9-
using Ydb.Sdk.Services.Topic.Writer;
7+
using Ydb.Sdk.Topic;
8+
using Ydb.Sdk.Topic.Reader;
9+
using Ydb.Sdk.Topic.Writer;
1010

1111
namespace TopicService;
1212

@@ -332,7 +332,7 @@ int partitionId
332332
}
333333

334334
private static void CheckMessage(ConcurrentDictionary<long, ConcurrentQueue<string>> localStore,
335-
Ydb.Sdk.Services.Topic.Reader.Message<string> message)
335+
Ydb.Sdk.Topic.Reader.Message<string> message)
336336
{
337337
if (localStore.TryGetValue(message.PartitionId, out var partition))
338338
{
@@ -363,7 +363,7 @@ private static string PrintLocalStore(ConcurrentDictionary<long, ConcurrentQueue
363363
string.Join("\n", localStore.Select(pair => pair.Key + ": " + string.Join(", ", pair.Value))) +
364364
"]";
365365

366-
private static void AssertMessage(Ydb.Sdk.Services.Topic.Reader.Message<string> message, string expectedMessageData)
366+
private static void AssertMessage(Ydb.Sdk.Topic.Reader.Message<string> message, string expectedMessageData)
367367
{
368368
if (expectedMessageData == message.Data)
369369
{

src/Ydb.Sdk/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
- **Breaking Change**: `Ydb.Sdk.Services.Topic` moved to `Ydb.Sdk.Topic`.
2+
13
## v0.24.0
24

35
- **Breaking Change**: Renamed properties in `YdbConnectionStringBuilder`:
@@ -18,7 +20,7 @@
1820
- Fixed bug ADO.NET/PoolManager: `SemaphoreSlim.WaitAsync` over-release on cancellation.
1921
- Feat ADO.NET: Mark `YdbConnection.State` as `Broken` when the underlying session is broken, including background deactivation.
2022
- Feat ADO.NET: Added YdbDataSource `ExecuteAsync` and `ExecuteInTransaction` convenience methods.
21-
- **Breaking Change**: moved and renamed `Ydb.Sdk.Services.Query.TxMode` -> `Ydb.Sdk.Ado.TransactionMode`.
23+
- **Breaking Change**: `Ydb.Sdk.Services.Query.TxMode` moved to `Ydb.Sdk.Ado.TransactionMode`.
2224
- Feat ADO.NET: Cache gRPC transport by `gRPCConnectionString` to reuse channels.
2325
- Fixed bug wrap-around ADO.NET: Big parameterized Decimal — `((ulong)bits[1] << 32)` -> `((ulong)(uint)bits[1] << 32)`.
2426
- Feat ADO.NET: Parameterized Decimal overflow check: `Precision` and `Scale`.

src/Ydb.Sdk/src/Services/Topic/Deserializer.cs renamed to src/Ydb.Sdk/src/Topic/Deserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Text;
22

3-
namespace Ydb.Sdk.Services.Topic;
3+
namespace Ydb.Sdk.Topic;
44

55
public interface IDeserializer<out TValue>
66
{

src/Ydb.Sdk/src/Services/Topic/Exceptions.cs renamed to src/Ydb.Sdk/src/Topic/Exceptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Ydb.Sdk.Services.Topic;
1+
namespace Ydb.Sdk.Topic;
22

33
public class WriterException : Exception
44
{

src/Ydb.Sdk/src/Services/Topic/IReader.cs renamed to src/Ydb.Sdk/src/Topic/IReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using Ydb.Sdk.Services.Topic.Reader;
1+
using Ydb.Sdk.Topic.Reader;
22

3-
namespace Ydb.Sdk.Services.Topic;
3+
namespace Ydb.Sdk.Topic;
44

55
public interface IReader<TValue> : IAsyncDisposable
66
{

src/Ydb.Sdk/src/Services/Topic/IWriter.cs renamed to src/Ydb.Sdk/src/Topic/IWriter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using Ydb.Sdk.Services.Topic.Writer;
1+
using Ydb.Sdk.Topic.Writer;
22

3-
namespace Ydb.Sdk.Services.Topic;
3+
namespace Ydb.Sdk.Topic;
44

55
public interface IWriter<TValue> : IAsyncDisposable
66
{
@@ -13,7 +13,7 @@ public interface IWriter<TValue> : IAsyncDisposable
1313
/// A Task which will complete with a delivery report corresponding to the produce request,
1414
/// or an exception if an error occured.
1515
/// </returns>
16-
/// <exception cref="T:Ydb.Sdk.Services.Topic.WriterException">
16+
/// <exception cref="Ydb.Sdk.Topic.WriterException">
1717
/// Thrown in response to any write request that was unsuccessful for any reason.
1818
/// </exception>
1919
public Task<WriteResult> WriteAsync(TValue data, CancellationToken cancellationToken = default);
@@ -27,7 +27,7 @@ public interface IWriter<TValue> : IAsyncDisposable
2727
/// A Task which will complete with a delivery report corresponding to the produce request,
2828
/// or an exception if an error occured.
2929
/// </returns>
30-
/// <exception cref="T:Ydb.Sdk.Services.Topic.WriterException">
30+
/// <exception cref="Ydb.Sdk.Topic.WriterException">
3131
/// Thrown in response to any write request that was unsuccessful for any reason.
3232
/// </exception>
3333
public Task<WriteResult> WriteAsync(Message<TValue> message, CancellationToken cancellationToken = default);

0 commit comments

Comments
 (0)