O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hands-On Microservices with C#

Book Description

Build enterprise-grade microservice ecosystems with intensive case studies using C#

About This Book
  • Learn to build message-based microservices
  • Packed with case studies to explain the intricacies of large-scale microservices
  • Build scalable, modular, and robust architectures with C#
Who This Book Is For

C# developers, software architects, and professionals who want to master the art of designing the microservice architecture that is scalable based on environment. Developers should have a basic understanding of.NET application development using C# and Visual Studio

What You Will Learn
  • Explore different open source tools within the context of designing microservices
  • Learn to provide insulation to exception-prone function calls
  • Build common messages used between microservices for communication
  • Learn to create a microservice using our base class and interface
  • Design a quantitative financial machine microservice
  • Learn to design a microservice that is capable of using Blockchain technology
In Detail

C# is a powerful language when it comes to building applications and software architecture using rich libraries and tools such as .NET.

This book will harness the strength of C# in developing microservices architectures and applications.

This book shows developers how to develop an enterprise-grade, event-driven, asynchronous, message-based microservice framework using C#, .NET, and various open source tools. We will discuss how to send and receive messages, how to design many types of microservice that are truly usable in a corporate environment. We will also dissect each case and explain the code, best practices, pros and cons, and more.

Through our journey, we will use many open source tools, and create file monitors, a machine learning microservice, a quantitative financial microservice that can handle bonds and credit default swaps, a deployment microservice to show you how to better manage your deployments, and memory, health status, and other microservices. By the end of this book, you will have a complete microservice ecosystem you can place into production or customize in no time.

Style and approach

A step-by-step guide that enables readers to create a complete microservice ecosystem they can place into production or customize in no time.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Hands-On Microservices with C#
  3. Packt Upsell
    1. Why subscribe?
    2. PacktPub.com
  4. Contributors
    1. About the author
    2. About the reviewers
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  6. Let's Talk Microservices, Messages, and Tools
    1. What is a microservice?
    2. Service-Oriented Architecture
    3. Microservice architecture
    4. Pros and cons
      1. Pros
      2. Cons
    5. Case study
    6. Messaging concepts
    7. Message queues
      1. Producer consumer queue
    8. Creating common messages
    9. Message subscriptions
    10. The subscription ID that you pass to subscribe is important
      1. Considerations when writing the subscribe callback delegate
      2. Using SubscribeAsync
      3. Canceling subscriptions
    11. Versioning messages
      1. How does message versioning work?
      2. Message versioning guidance
    12. Message publishing
    13. Message flow
    14. Exchanges
      1. Direct exchange
      2. Default exchange
      3. Topic exchange
      4. Fanout exchange
      5. Headers exchange
    15. Common messages
    16. Summary
  7. ReflectInsight – Microservice Logging Redefined
    1. Router
    2. Log Viewer
    3. Live Viewer
    4. Message navigation
      1. Message properties
      2. Watches
      3. Bookmarks
      4. Call Stack
    5. Advanced Search
      1. Quick Search
      2. Advanced Search
    6. Time zone formatting
    7. Auto Save/Purge
      1. Auto Save
      2. Auto Purge
    8. Configuration Editor
      1. Overview
      2. XML configuration
      3. Dynamic configuration
      4. Configuration Editor
    9. Summary
    10. Exercises
  8. Creating a Base Microservice and Interface
    1. Classes versus interfaces
    2. Creating our base project
    3. Creating a base interface
    4. Creating our base microservice class
      1. Variables
      2. Base microservice constructor
    5. Implementing our interface
    6. Publishing a memory update message
      1. Minimal microservice
    7. Summary
  9. Designing a Memory Management Microservice
    1. Creating our microservice
    2. Our code
    3. Reclaiming memory
    4. Dynamically creating an exchange
    5. Dynamically creating a queue
    6. Publishing a message
    7. Summary
    8. Exercises
  10. Designing a Deployment Monitor Microservice
    1. Deployment issues
    2. Installation
    3. Our messages
      1. Deployment start message
        1. Deployment stop message
    4. Our program
    5. Subscribing to messages
    6. Processing messages
      1. Publishing health status messages
    7. Summary
    8. Exercises
  11. Designing a Scheduling Microservice
    1. Installation
    2. Installing Quartz.NET
    3. What is Quartz.NET?
      1. Runtime environments
      2. Job scheduling
      3. Job execution
      4. Job persistence
      5. Clustering
      6. Listeners and plugins
    4. Installing Quartz.NET server as a service
    5. Our program
    6. OnStart
    7. Scheduling multiple jobs
    8. Running our microservice
    9. Summary
    10. Exercises
  12. Designing an Email Microservice
    1. Installation
    2. Our program
      1. OnStart
      2. Subscribing to messages
      3. Processing messages
      4. Finding DNS servers
      5. Subscribing to email requests
    3. Summary
    4. Exercises
  13. Designing a File Monitoring Microservice
    1. Overview of FileSystemWatcher
      1. Internal buffer
    2. Building your microservice – part one
      1. Making sure our message queue and exchange are created
      2. Running the recovery filewatcher
    3. Building your microservice – part two
      1. Our message
      2. Building our main program
      3. Notes on events
    4. Summary
    5. Exercises
  14. Creating a Machine Learning Microservice
    1. Installation
    2. Our program
      1. OnStart
    3. Processing a machine learning request
      1. Creating a layer
      2. Creating a network
      3. Traversing the forward path through the network
      4. Training the network
      5. Getting results
    4. Summary
  15. Creating a Quantitative Financial Microservice
    1. Installation
    2. Our messages
      1. CDS-request message
        1. Bonds request message
      2. Subscribing to messages
      3. Publishing our request message
      4. Publishing our CDS response
      5. Calculating a CDS
    3. Getting bond information
    4. Processing a bond request
    5. Processing a bond response
    6. Summary
    7. Exercises
  16. Trello Microservice – Board Status Updating
    1. Installation
      1. Creating boards, lists, and cards
    2. Summary
    3. Exercises
  17. Microservice Manager – The Nexus
    1. Installation
      1. Our code
        1. Leader election
      2. Subscribing to all messages
        1. Processing bond response messages
        2. Processing deployment messages
        3. Processing CDS messages
        4. Processing memory messages
        5. Processing health status messages
        6. Processing machine learning messages
        7. Processing filesystem messages
    2. Summary
    3. Exercises
  18. Creating a Blockchain Bitcoin Microservice
    1. Blockchain
      1. Bitcoin
      2. Digital signatures
      3. The circle of encryption
    2. Installation
    3. Our main program
      1. Leader election
    4. Creating our digital wallet
      1. Your public address
    5. How do we spend money?
    6. Our code
      1. Processing BitcoinSpendReceipt
    7. Summary
    8. Exercises
  19. Adding Speech and Search to Your Microservice
    1. Text-to-Speech
    2. Installation
    3. Our program
    4. Our messages
    5. Subscribing to messages
    6. Processing speech request messages
    7. Processing Wikipedia search messages
    8. Using Text-to-Speech
    9. Summary
  20. Best Practices
    1. Microservices
    2. Messaging
    3. Scheduling jobs
    4. Recommended reading