Getting started with Queues in .NET using AWS SQS

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.ค. 2024
  • Get $50 free AWS Credit by adding "AWS CREDIT #NICK" in the "Tell us about your project" area: bit.ly/nickaws
    Get the source code: github.com/Elfocrash/aws-videos
    Check out my courses: dometrain.com
    Become a Patreon and get source code access: / nickchapsas
    This video is sponsored by AWS
    Hello everybody I'm Nick and in this video I will show you how you can get started with Queues in C# and .NET by using the AWS SQS service. Queues are a crucial part of any microservice architecture system and SQS is one of the most popular AWS services. Knowing how to use it is a critical part of any software engineer's skillset.
    Don't forget to comment, like and subscribe :)
    Timestamps
    Intro & creating the SQS Queue - 0:00
    Creating the Publisher - 5:29
    Creating the Consumer - 14:59
    Extending the consumer with handlers - 23:00
    Automatic registration refactoring - 35:38
    Video on queues: • What is Azure Service ...
    Social Media:
    Follow me on GitHub: bit.ly/ChapsasGitHub
    Follow me on Twitter: bit.ly/ChapsasTwitter
    Connect on LinkedIn: bit.ly/ChapsasLinkedIn
    Keep coding merch: keepcoding.shop
    #aws #dotnet #sqs

ความคิดเห็น • 75

  • @7th_CAV_Trooper
    @7th_CAV_Trooper 2 ปีที่แล้ว +4

    This is the best C# channel on TH-cam x 10. Sometimes it's like Nick has access to my backlog and makes videos just for me.

  • @lucasteles42
    @lucasteles42 2 ปีที่แล้ว +3

    A simpler way to have it working nice is with Mediatr, the background service does de parse and dispatch of the messages

  • @p4xx07
    @p4xx07 2 ปีที่แล้ว +7

    I would like to see the covariance and contravariance one!

  • @tntomek
    @tntomek ปีที่แล้ว +2

    Your channel is amazing. It's perfectly in-depth enough to lean and start doing. As requested, more AWS + .NET Architecture videos please.

  • @ecoreyelias
    @ecoreyelias ปีที่แล้ว

    This is honestly my favorite video. So many good patterns and examples. Hats off.

  • @sunsei104
    @sunsei104 2 ปีที่แล้ว

    Can't wait for the architecture video ! Keep up the good work !

  • @FarukLuki111
    @FarukLuki111 2 ปีที่แล้ว

    I like the fact that your videos and Topics are getting "bigger" and more detailed! thx

  • @mehdizeynalov1062
    @mehdizeynalov1062 ปีที่แล้ว

    Nick your videos are just what is required, a true scientist... well done man.

  • @winstonstrongarm8929
    @winstonstrongarm8929 2 ปีที่แล้ว +12

    Yesssssssss, been waiting for this, I've done a few implementations in my projects but I've never been fully happy with it. Would love to see more videos on proper async data pipelines/flows👍 thanks for doing these videos man, I dropped out in first year of my Cs degree and while I can code, I always feel lacking on the infrastructure/architecture side. Your courses and videos have been a massive help for me🙏

  • @Daanik8
    @Daanik8 2 ปีที่แล้ว

    Hey Nick, great video! Thank you bringing such quality content!

  • @paulscarlett4346
    @paulscarlett4346 2 ปีที่แล้ว

    Great info... having used MSMQ for over 10 years for Process Control.. nice to see a modern implementation of a message dispatcher

    • @q1joe
      @q1joe 2 ปีที่แล้ว

      I mean even 10 years ago MSMQ wasn't "modern". Wondering why it was ever picked after 2008.

  • @kazepis
    @kazepis 2 ปีที่แล้ว

    Really nice video! Congrats! And as always, keep them coming… 🎉

  • @DanielAlvaradoB
    @DanielAlvaradoB 2 หลายเดือนก่อน

    Eyy, this was super helpful and very easy to follow. Thank you! 🙏

  • @pedroh.franco
    @pedroh.franco 2 ปีที่แล้ว

    Congratulations Nick, as always a good video.

  • @rafalschmidt1183
    @rafalschmidt1183 2 ปีที่แล้ว +8

    I would love to see different techniques how to tackle idempotency! I've seen many different approaches and would be great to compare with what you've seen.

    • @alissonhonostorio
      @alissonhonostorio 2 ปีที่แล้ว +1

      The message received by SQS has one property messageId and that id is unique no metter how many times this message is delivered, a simple way to deal with this idempotency is saving this Id

  • @pdevito
    @pdevito 2 ปีที่แล้ว +2

    Cool video! I’d probably prefer to use a message bus like mass transit to abstract most of this out for me, but still fun to see it built too

  • @iamaashishpatel
    @iamaashishpatel 2 ปีที่แล้ว

    As usual, awesome content. 🙏

  • @Vinoyl
    @Vinoyl 2 ปีที่แล้ว

    I love how you're releasing these AWS videos a few months after I had to figure it all out myself lol

  • @jamesevans6438
    @jamesevans6438 2 ปีที่แล้ว

    Hey Nick, awesome video, thanks so much for the great content and for sharing. Would be interested in how to deal with idempotency too. Looking forward to the solution architecture video too.

  • @evildoer1606
    @evildoer1606 2 ปีที่แล้ว

    Yo Nick! I'm Xamarin dev that switched to backend half a year ago. Old viewer of yours, but now - your channel is a real GEM for me, every new video I watch is exactly what I need, just started my AWS journey and the timing of this one is magic. Thank you for your content! Also I really want to see a bonkers approach with Handlers and more AWS content overall.

    • @craigfranchuk9339
      @craigfranchuk9339 2 ปีที่แล้ว

      I've been using this approach for processing messages via the azure service bus since generic host (background service) released in .net core 2.1. Thanks for producing these videos, I find the content very useful and practical.

  • @wh33lers
    @wh33lers 2 ปีที่แล้ว

    Thanks for sharing all those details. I am also using SQS very intensively and love the service for its simplicity. Keep it up

  • @timothywestern6488
    @timothywestern6488 2 ปีที่แล้ว

    So this is a fascinating idea.
    The way you described Standard AWS QUeue sounds like a prioritized asynchronous queue.
    I can imagine a queue where all of these items are waiting to be processed, and as product becomes available it can be filled by the first order that asks for it, maybe.
    But its potentially optimizable because if you have someone in slot 3 asking for grapes, but slot 2 wants grapes and pomegranates but the pomegranets are delayed (and maybe you optimize to try to fill what you can complete, and if it ends up getting stuck then getting intervention somehow to break the queued item up. AWS could optimize to look for the first item in the queue that can be filled and dispatched. So I think I really like this idea, because its not like you have competing tasks waiting to be filled and potential contention that way. Pretty cool!

  • @euanmair55
    @euanmair55 2 ปีที่แล้ว +1

    Hi Nick, great video as always. Is there any chance you could do a video on Amazon Cognito? i.e. basic setup and walkthrough

  • @Couper44
    @Couper44 2 ปีที่แล้ว

    Hey Nick, great video, please do more about queues and how to efficiently publish/consume messages 🙏.
    Kind of unrelated, but it would make sense to put together handler's registration and populating MessageDispatcher's dictionaries? (to avoid forgetting registering them in Program.cs)
    Many thanks!

    • @jfpinero
      @jfpinero 2 ปีที่แล้ว

      No need for dictionaries, just use something like Scrutor to automatically register stuff

  • @SlackwareNVM
    @SlackwareNVM 2 ปีที่แล้ว +1

    I'd love to see a video for the generic message handling. That scenario comes up way too often.

  • @yonatandaniyel5640
    @yonatandaniyel5640 9 หลายเดือนก่อน

    Great video and pretty slick use of reflection to handle registering your services in the service container. Do you have a video that would utilize SNS and also display how the messages are deleted from the Queue? Also, would be nice to see the use of the DLQ for failed messages.

  • @xieweiling7543
    @xieweiling7543 2 ปีที่แล้ว

    Awesome video, although the last part 'Automatic registration refactoring' is a little bit hard and rush.

  • @m1kecrosoft
    @m1kecrosoft ปีที่แล้ว

    I tried to run this project in dotnet 7 but it fails because IMessageHandler can be used as a type. Then I downgrade to dotnet 6 but I can use abstract in the property IMessageHandler.MessageType so I have to initialize that property with typeof(IMessageHandler), it is good ?

  • @Fran-bo7vg
    @Fran-bo7vg ปีที่แล้ว

    Can one use NServicebus with SQS and not worry about implementing a custom dispatcher logic?

  • @xMsDanielx
    @xMsDanielx 2 ปีที่แล้ว

    Hi Nick. Maybe in the near future you could create video about SAGAs?

  • @emmanueladebiyi2109
    @emmanueladebiyi2109 ปีที่แล้ว

    Looks like you ended up not using the static abstract interface members feature as the reflection scanning would work regardless. Right?

  • @ThiNguyen-bm5ln
    @ThiNguyen-bm5ln 2 หลายเดือนก่อน

    Hey Nick. Thanks for the video. I have a question though. If the published message is subscribed by multiple applications (or I can say users), how do we make sure all the users see the message before it gets deleted? (If we don't delete the message, one user might end up seeing the message multiple times)

  • @davidheale6435
    @davidheale6435 2 ปีที่แล้ว

    Hey Nick, you don't have a link in the description below for Queues.

  • @crazyfox55
    @crazyfox55 2 ปีที่แล้ว

    Your comment about the messages being in a shared project instead of duplicating the files is a good one. However when you used the executing assembly it will not find those messages, instead typeof(IMessage).Assembly would be better. Same concept for the IMessageHandler.

    • @nickchapsas
      @nickchapsas  2 ปีที่แล้ว +2

      Yeah I did mention that you would use a type or an assembly if you had it in a separate project

    • @crazyfox55
      @crazyfox55 2 ปีที่แล้ว +1

      @@nickchapsas Now that I think about it more, like you said most developers would have understood to use typeof(IMessage) instead of typeof(Program) if they moved the files to a separate project.

  • @johncerpa3782
    @johncerpa3782 2 ปีที่แล้ว +1

    Great video, reduce font size please

  • @benjaminweber2598
    @benjaminweber2598 2 ปีที่แล้ว

    Hi Nick! Do you use Azure (in this case the service bus) as well and can you make a comparison, or are you only on AWS?

    • @nickchapsas
      @nickchapsas  2 ปีที่แล้ว

      I’ve used both in high scale production environments for 3 years each and I prefer AWS.

    • @benjaminweber2598
      @benjaminweber2598 2 ปีที่แล้ว +1

      @@nickchapsas interesting, i would love to see a video about the reasons some day :)

  • @regeface
    @regeface 2 ปีที่แล้ว

    Very nice video. Any chance of making a similar vid with MassTransit?

    • @nickchapsas
      @nickchapsas  2 ปีที่แล้ว +2

      I plan to make an expansion on this video to show how MassTransit can make all this better

  • @01mrsir
    @01mrsir 2 ปีที่แล้ว +2

    Great vid bro... can you do some on Dapr?

  • @ksysio0o
    @ksysio0o ปีที่แล้ว

    Amazing content and great explanations. But for a more pleasant reception, I would advise 10% slower. It isn't a chase :).

  • @shoooozzzz
    @shoooozzzz ปีที่แล้ว

    Did you just write your own MediatR? =)

  • @NameSurname-zm7gl
    @NameSurname-zm7gl 2 ปีที่แล้ว

    heh, I decided to implement MessageDispatcher with generics, and it was the worse decision for the last few days) Could you please make a video\another branch in github with implementation in the way with generics/variance stuff.

    • @nickchapsas
      @nickchapsas  2 ปีที่แล้ว +1

      I’m planning to use this example in a future video to explain the runtime problems (which you probably encountered), variance and alternatives

    • @NameSurname-zm7gl
      @NameSurname-zm7gl 2 ปีที่แล้ว

      @@nickchapsas That would be awesome. Thanks

  • @ali_randomNumberHere
    @ali_randomNumberHere 2 ปีที่แล้ว

    sadly we cant use aws services in iran,thats just make me feel depressed

  • @amrosamy8232
    @amrosamy8232 2 ปีที่แล้ว

    For the dispatcher, I'd create an IEnumerable
    IMessageHandler can contains
    {
    string Command {get => nameof(MessageType)}
    Type MessageType {get;}
    Task HandleAsync ();
    }
    Then register all handlers as IMessageHandler
    Finally inject IEnumerable in the constructor
    Using linq
    var handlers = msgHandlers.Where(mh => mh.Command == input.commans )
    foreach(var handler in handlers) await handler.HandleAsync(input.Data);

    • @nickchapsas
      @nickchapsas  2 ปีที่แล้ว +2

      This approach is problematic because it instantiates all handlers to just use one. waste of speed and memory

    • @amrosamy8232
      @amrosamy8232 2 ปีที่แล้ว

      Make sense, that's why you created a dictionary

    • @DarraghJones
      @DarraghJones 2 ปีที่แล้ว +1

      Unnecessarily instantiating handlers aside, i like this approach. I would probably introduce an abstract base class like this:
      public abstract class MessageHandler : IMessageHandler where TMessage : IMessage
      {
      public async Task HandleAsync(IMessage message)
      {
      if (messageis TMessage m)
      {
      await DoHandleAsync(m);
      }
      }
      protected abstract Task DoHandleAsync(TMessage m);
      }
      so my MessageDispatcher is nice a simple like this:
      public class MessageDispatcher
      {
      private readonly IServiceScopeFactory scopeFactory;
      public MessageDispatcher(IServiceScopeFactory scopeFactory)
      {
      this.scopeFactory = scopeFactory;
      }
      public async Task Dispatch(IMessage m)
      {
      using var scope = scopeFactory.CreateScope();
      foreach (var handler in scope.ServiceProvider.GetServices())
      {
      await handler.HandleAsync(m);
      }
      }
      }
      This way you can also write handlers which work off a base message type for instance:
      public class AllMessagesHandler : MessageHandler
      {
      protected override Task DoHandleAsync(IMessage m)
      {
      Console.WriteLine(m.GetType());
      return Task.CompletedTask;
      }
      }

  • @anandjaisy
    @anandjaisy 2 ปีที่แล้ว

    Hey mate, your videos are so useful, can you please make a video on comparison between Entity Framework latest vs Dapper. Why we should use dapper over entity framework and use cases.

  • @IsaacOjeda
    @IsaacOjeda 2 ปีที่แล้ว

    👏🏽👏🏽👏🏽👏🏽👏🏽

  • @nishadhkhan974
    @nishadhkhan974 2 ปีที่แล้ว

    @Nick Chapas, How can i rate limit a specific api which url contains and require int value.
    E.g
    api/account/details - This is like you explained - which is working
    but what in case if url is like this?
    api/account/{accountId:int}/details
    Please help me. im using webapi2

  • @NameSurname-zm7gl
    @NameSurname-zm7gl 2 ปีที่แล้ว

    5:13 Am I only one person who expected a random id as 69

  • @metaltyphoon
    @metaltyphoon 2 ปีที่แล้ว +3

    I never understand the obsession with adding `Async` to methods where you don't provide a sync version of it. It's just fluff. Everyone knows a task can be awaited

    • @nickchapsas
      @nickchapsas  2 ปีที่แล้ว +2

      Then in the code that you write you should definitely not use that suffix

    • @metaltyphoon
      @metaltyphoon 2 ปีที่แล้ว

      @@nickchapsas I definitely don’t. In fact calling it Async may be a lie. See MemoryStream for example. I also don’t add access modifiers just because; only when necessary.

    • @metaltyphoon
      @metaltyphoon 2 ปีที่แล้ว

      @@ShiyalaKohny To clarify, I never meant to be rude and if that’s how it came across, I want you to know it wasn’t the case @Nick Chapsas.

    • @metaltyphoon
      @metaltyphoon 2 ปีที่แล้ว

      @@paulkoopmans4620 Microsoft don’t even follow their own conventions on their asp code base 😂. Async is just noise as is typing private for private members.

    • @paulkoopmans4620
      @paulkoopmans4620 2 ปีที่แล้ว

      ​@@metaltyphoonnot sure which occurrences you are thinking of at this moment. But... no framework and/or programming is ever 100% correct. That does not mean however that "standards" and trying to follow them is bad. Quite the opposite IMHO.
      I will admit that I come back to my code at times thinking... wt... why did I just not follow the coding style guide or why I not do this or that. But I am a human and so are they.
      But if nothing would have existed at all.... oh boy... I can just imagine how terrible that must be. Property names will all kinds of different casing. Terrible method names like b_convstr() instead of TryConvertString(), just because, you know. No!!! No!!! No!!! Even though never perfect, millions of developers following a "standard" is better than nothing.
      And again; I personally believe in intent of code. If a member is a private member it should be marked as such. If it were up to me I would say the implicit access modifier behaviour should have never existed. It serves no purpose! the "choice" of private as the default access modifier is as terrible of a choice as any of the other ones.
      My classes are usually sprinkled with lots of public methods, public properties, protected, etc, as well. I think I may usually have more of any of the other ones than private. Maybe public should have been the default :).

  • @massaynus
    @massaynus 2 ปีที่แล้ว

    god forbid any poor soul has to write such C#

  • @Ristogod
    @Ristogod 2 ปีที่แล้ว +2

    Yeah, get on AWS, so they can turn you off if you have the "wrong ideas". No thanks.

    • @marcinpawelw
      @marcinpawelw 2 ปีที่แล้ว +1

      While I agree with you, I believe that regular developers don't need to worry about it as much as our clients - they're the ones that amazon might refuse service. We can only advise them not to use services from providers who might be unreliable like that.

    • @maskettaman1488
      @maskettaman1488 2 ปีที่แล้ว

      @@marcinpawelw The problem arises when it's your own AWS-backed service that a client is using. They can wrongthink your entire service in to the ground. Not a liability I want to take on

  • @emanuelcordovamontiel1017
    @emanuelcordovamontiel1017 2 หลายเดือนก่อน

    I like your videos but you speak so fast. Could you speak more slowly, please?