YaCloudKit.MQ 0.2.1

Suggested Alternatives

YaCloudKit.MQ 0.8.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package YaCloudKit.MQ --version 0.2.1
NuGet\Install-Package YaCloudKit.MQ -Version 0.2.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="YaCloudKit.MQ" Version="0.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add YaCloudKit.MQ --version 0.2.1
#r "nuget: YaCloudKit.MQ, 0.2.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install YaCloudKit.MQ as a Cake Addin
#addin nuget:?package=YaCloudKit.MQ&version=0.2.1

// Install YaCloudKit.MQ as a Cake Tool
#tool nuget:?package=YaCloudKit.MQ&version=0.2.1

YaCloudKit.MQ

YaCloudKit.MQ - неофицальный клиент для работы с очередью сообщений Yandex Message Queue, используемый для обмена сообщениями между компонентами распределённых приложений и микросервисов.

Библиотека YaCloudKit.MQ полностью адаптирова под сервис Yandex Message Queue и, в отлиции от AWS.SQS, не имеет лишних неиспользуемых зависимостей и кода, что значительно уменьшает используемые ресурсы.

Вы с легкостью можете создать клиент, без указания лишних параметров. Просто создайте новый экземпляр YandexMqClient с указанием идентификатора ключа доступа и секретного ключа и начинайте отправлять или принимать сообщения:

var mq = new YandexMqClient("AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY");

// some work...

Возможности

YaCloudKit.MQ реализует полный функционал описанный в документации сервиса для работы с очередями и сообщениями и позволяет выполнять следующие операции:

  • Создавать очереди сообщений
  • Удалять очереди сообщений
  • Запрашивать атрибуты очереди сообщений
  • Изменять атрибуты очереди сообщений
  • Запрашивать URL очереди сообщений
  • Запрашивать список очередей сообщений
  • Очищать очередь сообщений
  • Отправлять сообения
  • Запрашивать сообщения
  • Устанавливать тайм-аут видимости обрабатываемого сообщения/сообщений
  • Удалять сообщения

Начало работы

YaCloudKit.MQ устанавливается из NuGet. Для работы библиотеки нужно так же установить основную зависимость:

Install-Package YaCloudKit.Core
Install-Package Serilog.MQ

После установки вы можете приступать к использованияю клиента. Следующий пример демонстрирует быстрое создание и конфигурирование клиента для последующей отправки сообщения в очередь:

var mq = new YandexMqClient("AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY");

var sendRequest = new SendMessageRequest()
{
    QueueUrl = "https://message-queue.api.cloud.yandex.net/...",
    MessageBody = "Hello message!"
};

try
{
    var sendResponse = await mq.SendMessageAsync(sendRequest);
    Console.WriteLine("Status code: " + sendResponse.HttpStatusCode);
    Console.WriteLine("Message id: " + sendResponse.MessageId);
    Console.WriteLine("MD5: " + sendResponse.MD5OfMessageBody);
}
catch (YandexMqServiceException ex)
{
    Console.WriteLine("Status code: " + ex.StatusCode);
    Console.WriteLine("Request id: " + ex.RequestId);
    Console.WriteLine("Type: " + ex.ErrorType);
    Console.WriteLine("Error code: " + ex.ErrorCode);
    Console.WriteLine("Message: " + ex.Message);
}

Если вам необходимо получить сообщения из очереди вы можете сделать это следующим образом:

 var mq = new YandexMqClient("AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY");

var receiveRequest = new ReceiveMessageRequest()
{
    QueueUrl = "https://message-queue.api.cloud.yandex.net/...",
    WaitTimeSeconds = 20 // установка значения ожидания для long-polling запроса
};

try
{
    var receiveResponse = await mq.ReceiveMessageAsync(receiveRequest);
    Console.WriteLine("Status code: " + receiveResponse.HttpStatusCode);
    foreach(var message in receiveResponse.Messages)
    {
        Console.WriteLine("\r\nMessage id: " + message.MessageId);
        Console.WriteLine("\tReceiptHandle: " + message.ReceiptHandle);
        Console.WriteLine("\tMD5: " + message.MD5OfBody);
        Console.WriteLine("\tBody: " + message.Body);

        // Удаляем сообщение из очереди после обработки
        var deleteRequest = new DeleteMessageRequest() {
            QueueUrl = "https://message-queue.api.cloud.yandex.net/...",
            ReceiptHandle = message.ReceiptHandle,
        };
        _ = await mq.DeleteMessageAsync(deleteRequest);                    
    }
}
catch (YandexMqServiceException ex)
{
    Console.WriteLine("Status code: " + ex.StatusCode);
    Console.WriteLine("Request id: " + ex.RequestId);
    Console.WriteLine("Type: " + ex.ErrorType);
    Console.WriteLine("Error code: " + ex.ErrorCode);
    Console.WriteLine("Message: " + ex.Message);
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on YaCloudKit.MQ:

Package Downloads
YaCloudKit.MQ.Transport

Инструмент YaCloudKit для работы с очередью сообщений Yandex Cloud

YaCloudKit.MQ.Extensions.DependencyInjection

Реализация методов регистраици зависимостей для YaCloudKit.MQ

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.8.0 8,449 10/30/2022
0.5.8 925 10/5/2022
0.5.7 667 9/18/2022
0.5.6 638 9/16/2022
0.5.5 499 9/13/2022
0.4.4 395 9/13/2022
0.3.6 396 9/13/2022
0.3.5 732 7/21/2022
0.3.4 414 7/21/2022
0.3.2 403 9/13/2022
0.3.1 402 7/21/2022
0.3.0 417 7/21/2022
0.2.3 7,762 6/4/2022
0.2.2 4,854 6/10/2021
0.2.1 645 4/12/2021
0.2.0 574 4/2/2021
0.1.1 616 1/24/2021
0.1.0 615 1/20/2021