Orleans Stocks sample app
This application fetches stock prices from a remote service using HttpClient
, caches them in a grain, and displays them on screen.
Demonstrates
- How to use Orleans from within a
BackgroundService
. - How to use timers within a grain
- How to make external service calls using .NET's
HttpClient
and cache the results within a grain.
A BackgroundService
periodically requests the stock price for a variety of stocks from corresponding StockGrain
instances.
Each StockGrain
is identified by its stock ticker symbol, for example, the string "MSFT"
.
For the sample to display all of the stocks included, it requires replacing the ApiKey
constant in StockGrain.cs
with an API key obtained from https://www.alphavantage.co/support/#api-key.
The sample can be run without replacing this key, but a warning message may be printed with directions on how to obtain an API key.
Sample prerequisites
This sample is written in C# and targets .NET 8.0. It requires the .NET 8.0 SDK or later.
Building the sample
To download and run the sample, follow these steps:
- Download and unzip the sample.
- In Visual Studio (2022 or later):
- On the menu bar, choose File > Open > Project/Solution.
- Navigate to the folder that holds the unzipped sample code, and open the C# project (.csproj) file.
- Choose the F5 key to run with debugging, or Ctrl+F5 keys to run the project without debugging.
- From the command line:
- Navigate to the folder that holds the unzipped sample code.
- At the command line, type
dotnet run
.