Skip to content

Instantly share code, notes, and snippets.

@thomaslazar
Created September 21, 2018 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomaslazar/c704d0321b7f08c2eaeee1dfec1df4ef to your computer and use it in GitHub Desktop.
Save thomaslazar/c704d0321b7f08c2eaeee1dfec1df4ef to your computer and use it in GitHub Desktop.
Akka.net Streams derping around
namespace StreamingServer
{
using System;
using System.Linq;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.Streams;
using Akka.Streams.Dsl;
public class Program
{
public static async Task Main(string[] args)
{
//var source = Source.From(Enumerable.Range(1, 100));
//using (var system = ActorSystem.Create("system"))
//using (var materializer = system.Materializer())
//{
// await source.RunForeach(i => Console.WriteLine(i.ToString()), materializer);
//}
Startup.StartServerActorSystem();
for (int i = 1; i <= 1000; i++)
{
//StreamingServerActorRefs.DataSourceActor.Tell(new Tuple<DateTime, double>(DateTime.Now, new Random().Next(1, 500)));
var tuple = new Tuple<DateTime, double>(DateTime.Now, i);
StreamingServerActorRefs.DataSourceActor.Tell(tuple);
Console.WriteLine($"{new DateTimeOffset(tuple.Item1).ToUnixTimeMilliseconds().ToString()}, {tuple.Item2}");
}
Console.WriteLine("done.");
Console.ReadKey();
}
}
}
1537558794905 1
1537558794907 2
1537558794907 3
1537558794907 4
1537558794907 5
1537558794907 6
1537558794907 7
1537558794907 8
1537558794907 9
1537558794907 10
1537558794907 11
1537558794907 12
1537558794907 13
1537558794907 14
1537558794907 15
1537558794907 16
1537558794907 17
1537558794907 18
1537558794907 19
1537558794907 20
1537558794907 21
1537558794907 22
1537558794907 23
1537558794907 24
1537558794907 25
1537558794907 26
1537558794907 27
1537558794907 28
1537558794907 29
1537558794907 30
1537558794907 31
1537558794907 32
1537558794907 33
1537558794907 34
1537558794908 35
1537558794908 36
1537558794908 37
1537558794908 38
1537558794908 39
1537558794908 40
1537558794908 41
1537558794908 42
1537558794908 43
1537558794908 44
1537558794908 45
1537558794908 46
1537558794908 47
1537558794908 48
1537558794908 49
1537558794908 50
1537558794908 51
1537558794908 52
1537558794908 53
1537558794908 54
1537558794908 55
1537558794908 56
1537558794908 57
1537558794909 58
1537558794909 59
1537558794909 60
1537558794909 61
1537558794909 62
1537558794909 63
1537558794909 64
1537558794909 65
1537558794909 66
1537558794909 67
1537558794909 68
1537558794909 69
1537558794909 70
1537558794909 71
1537558794909 72
1537558794909 73
1537558794909 74
1537558794909 75
1537558794909 76
1537558794909 77
1537558794909 78
1537558794909 79
1537558794909 80
1537558794909 81
1537558794909 82
1537558794909 83
1537558794909 84
1537558794909 85
1537558794909 86
1537558794909 87
1537558794909 88
1537558794909 89
1537558794909 90
1537558794909 91
1537558794909 92
1537558794909 93
1537558794909 94
1537558794909 95
1537558794909 96
1537558794909 97
1537558794909 98
1537558794909 99
1537558794909 100
1537558794909 101
1537558794909 102
1537558794909 103
1537558794909 104
1537558794909 105
1537558794909 106
1537558794909 107
1537558794909 108
1537558794909 109
1537558794909 110
1537558794909 111
1537558794909 112
1537558794909 113
1537558794909 114
1537558794909 115
1537558794909 116
1537558794909 117
1537558794909 118
1537558794909 119
1537558794909 120
1537558794909 121
1537558794909 122
1537558794909 123
1537558794909 124
1537558794909 125
1537558794909 126
1537558794909 127
1537558794909 128
1537558794909 129
1537558794909 130
1537558794909 131
1537558794909 132
1537558794909 133
1537558794909 134
1537558794909 135
1537558794909 136
1537558794909 137
1537558794909 138
1537558794909 139
1537558794909 140
1537558794909 141
1537558794909 142
1537558794909 143
1537558794909 144
1537558794909 145
1537558794909 146
1537558794909 147
1537558794909 148
1537558794909 149
1537558794909 150
1537558794909 151
1537558794909 152
1537558794909 153
1537558794909 154
1537558794910 155
1537558794910 156
1537558794910 157
1537558794910 158
1537558794910 159
1537558794910 160
1537558794910 161
1537558794910 162
1537558794910 163
1537558794910 164
1537558794910 165
1537558794910 166
1537558794910 167
1537558794910 168
1537558794910 169
1537558794910 170
1537558794910 171
1537558794910 172
1537558794910 173
1537558794910 174
1537558794910 175
1537558794910 176
1537558794910 177
1537558794910 178
1537558794910 179
1537558794910 180
1537558794910 181
1537558794910 182
1537558794910 183
1537558794910 184
1537558794910 185
1537558794910 186
1537558794910 187
1537558794910 188
1537558794910 189
1537558794910 190
1537558794910 191
1537558794910 192
1537558794910 193
1537558794910 194
1537558794910 195
1537558794910 196
1537558794910 197
1537558794910 198
1537558794910 199
1537558794910 200
1537558794910 201
1537558794910 202
1537558794910 203
1537558794910 204
1537558794910 205
1537558794910 206
1537558794910 207
1537558794910 208
1537558794910 209
1537558794910 210
1537558794910 211
1537558794910 212
1537558794910 213
1537558794910 214
1537558794910 215
1537558794910 216
1537558794910 217
1537558794910 218
1537558794910 219
1537558794910 220
1537558794910 221
1537558794910 222
1537558794910 223
1537558794910 224
1537558794910 225
1537558794910 226
1537558794910 227
1537558794910 228
1537558794910 229
1537558794910 230
1537558794910 231
1537558794910 232
1537558794910 233
1537558794910 234
1537558794910 235
1537558794910 236
1537558794910 237
1537558794910 238
1537558794910 239
1537558794910 240
1537558794910 241
1537558794910 242
1537558794910 243
1537558794910 244
1537558794910 245
1537558794910 246
1537558794910 247
1537558794910 248
1537558794910 249
1537558794910 250
1537558794910 251
1537558794910 252
1537558794910 253
1537558794910 254
1537558794910 255
1537558794910 256
1537558794910 257
1537558794910 258
1537558794910 259
1537558794910 260
1537558794910 261
1537558794910 262
1537558794910 263
1537558794911 264
1537558794911 265
1537558794911 266
1537558794911 267
1537558794911 268
1537558794911 269
1537558794911 270
1537558794911 271
1537558794911 272
1537558794911 273
1537558794911 274
1537558794911 275
1537558794911 276
1537558794911 277
1537558794911 278
1537558794911 279
1537558794911 280
1537558794911 281
1537558794911 282
1537558794911 283
1537558794911 284
1537558794911 285
1537558794911 286
1537558794911 287
1537558794911 288
1537558794911 289
1537558794911 290
1537558794911 291
1537558794911 292
1537558794911 293
1537558794911 294
1537558794911 295
1537558794911 296
1537558794911 297
1537558794911 298
1537558794911 299
1537558794911 300
1537558794911 301
1537558794911 302
1537558794911 303
1537558794911 304
1537558794911 305
1537558794911 306
1537558794911 307
1537558794911 308
1537558794911 309
1537558794911 310
1537558794911 311
1537558794911 312
1537558794911 313
1537558794911 314
1537558794911 315
1537558794911 316
1537558794911 317
1537558794911 318
1537558794911 319
1537558794911 320
1537558794911 321
1537558794911 322
1537558794911 323
1537558794911 324
1537558794911 325
1537558794911 326
1537558794911 327
1537558794911 328
1537558794911 329
1537558794911 330
1537558794911 331
1537558794911 332
1537558794911 333
1537558794911 334
1537558794911 335
1537558794911 336
1537558794911 337
1537558794911 338
1537558794911 339
1537558794911 340
1537558794911 341
1537558794911 342
1537558794911 343
1537558794911 344
1537558794911 345
1537558794911 346
1537558794911 347
1537558794911 348
1537558794911 349
1537558794911 350
1537558794911 351
1537558794911 352
1537558794911 353
1537558794911 354
1537558794911 355
1537558794911 356
1537558794911 357
1537558794911 358
1537558794911 359
1537558794911 360
1537558794912 361
1537558794912 362
1537558794912 363
1537558794912 364
1537558794912 365
1537558794912 366
1537558794912 367
1537558794912 368
1537558794912 369
1537558794912 370
1537558794912 371
1537558794912 372
1537558794912 373
1537558794912 374
1537558794912 375
1537558794912 376
1537558794912 377
1537558794912 378
1537558794912 379
1537558794912 380
1537558794912 381
1537558794912 382
1537558794912 383
1537558794912 384
1537558794912 385
1537558794912 386
1537558794912 387
1537558794912 388
1537558794912 389
1537558794912 390
1537558794912 391
1537558794912 392
1537558794912 393
1537558794912 394
1537558794912 395
1537558794912 396
1537558794912 397
1537558794912 398
1537558794912 399
1537558794912 400
1537558794912 401
1537558794912 402
1537558794912 403
1537558794912 404
1537558794912 405
1537558794912 406
1537558794912 407
1537558794912 408
1537558794912 409
1537558794912 410
1537558794912 411
1537558794912 412
1537558794912 413
1537558794912 414
1537558794912 415
1537558794912 416
1537558794912 417
1537558794912 418
1537558794912 419
1537558794912 420
1537558794912 421
1537558794912 422
1537558794912 423
1537558794912 424
1537558794912 425
1537558794912 426
1537558794912 427
1537558794912 428
1537558794912 429
1537558794912 430
1537558794912 431
1537558794912 432
1537558794912 433
1537558794912 434
1537558794912 435
1537558794912 436
1537558794912 437
1537558794912 438
1537558794912 439
1537558794912 440
1537558794912 441
1537558794912 442
1537558794912 443
1537558794912 444
1537558794912 445
1537558794912 446
1537558794912 447
1537558794912 448
1537558794912 449
1537558794913 450
1537558794913 451
1537558794913 452
1537558794913 453
1537558794913 454
1537558794913 455
1537558794913 456
1537558794913 457
1537558794913 458
1537558794913 459
1537558794913 460
1537558794913 461
1537558794913 462
1537558794913 463
1537558794913 464
1537558794913 465
1537558794913 466
1537558794913 467
1537558794913 468
1537558794913 469
1537558794913 470
1537558794913 471
1537558794913 472
1537558794913 473
1537558794913 474
1537558794913 475
1537558794913 476
1537558794913 477
1537558794913 478
1537558794913 479
1537558794913 480
1537558794913 481
1537558794913 482
1537558794913 483
1537558794913 484
1537558794913 485
1537558794913 486
1537558794913 487
1537558794913 488
1537558794913 489
1537558794913 490
1537558794913 491
1537558794913 492
1537558794913 493
1537558794913 494
1537558794913 495
1537558794913 496
1537558794913 497
1537558794913 498
1537558794913 499
1537558794913 500
1537558794913 501
1537558794913 502
1537558794913 503
1537558794913 504
1537558794913 505
1537558794913 506
1537558794913 507
1537558794913 508
1537558794913 509
1537558794913 510
1537558794913 511
1537558794913 512
1537558794913 513
1537558794913 514
1537558794913 515
1537558794913 516
1537558794913 517
1537558794913 518
1537558794913 519
1537558794913 520
1537558794913 521
1537558794913 522
1537558794913 523
1537558794913 524
1537558794913 525
1537558794914 526
1537558794914 527
1537558794914 528
1537558794914 529
1537558794914 530
1537558794914 531
1537558794914 532
1537558794914 533
1537558794914 534
1537558794914 535
1537558794914 536
1537558794914 537
1537558794914 538
1537558794914 539
1537558794914 540
1537558794914 541
1537558794914 542
1537558794914 543
1537558794914 544
1537558794914 545
1537558794914 546
1537558794914 547
1537558794914 548
1537558794914 549
1537558794914 550
1537558794914 551
1537558794914 552
1537558794914 553
1537558794914 554
1537558794914 555
1537558794914 556
1537558794914 557
1537558794914 558
1537558794914 559
1537558794914 560
1537558794914 561
1537558794914 562
1537558794914 563
1537558794914 564
1537558794914 565
1537558794914 566
1537558794914 567
1537558794914 568
1537558794914 569
1537558794914 570
1537558794914 571
1537558794914 572
1537558794914 573
1537558794914 574
1537558794914 575
1537558794914 576
1537558794914 577
1537558794914 578
1537558794914 579
1537558794914 580
1537558794914 581
1537558794914 582
1537558794914 583
1537558794914 584
1537558794914 585
1537558794914 586
1537558794914 587
1537558794914 588
1537558794914 589
1537558794914 590
1537558794914 591
1537558794914 592
1537558794914 593
1537558794914 594
1537558794914 595
1537558794914 596
1537558794914 597
1537558794914 598
1537558794915 599
1537558794915 600
1537558794915 601
1537558794915 602
1537558794915 603
1537558794915 604
1537558794915 605
1537558794915 606
1537558794915 607
1537558794915 608
1537558794915 609
1537558794915 610
1537558794915 611
1537558794915 612
1537558794915 613
1537558794915 614
1537558794915 615
1537558794915 616
1537558794915 617
1537558794915 618
1537558794915 619
1537558794915 620
1537558794915 621
1537558794915 622
1537558794915 623
1537558794915 624
1537558794915 625
1537558794915 626
1537558794915 627
1537558794915 628
1537558794915 629
1537558794915 630
1537558794915 631
1537558794915 632
1537558794915 633
1537558794915 634
1537558794915 635
1537558794915 636
1537558794915 637
1537558794915 638
1537558794915 639
1537558794915 640
1537558794915 641
1537558794915 642
1537558794915 643
1537558794915 644
1537558794915 645
1537558794915 646
1537558794915 647
1537558794915 648
1537558794915 649
1537558794915 650
1537558794915 651
1537558794915 652
1537558794915 653
1537558794915 654
1537558794915 655
1537558794915 656
1537558794915 657
1537558794915 658
1537558794915 659
1537558794915 660
1537558794915 661
1537558794915 662
1537558794915 663
1537558794915 664
1537558794915 665
1537558794915 666
1537558794915 667
1537558794915 668
1537558794915 669
1537558794915 670
1537558794915 671
1537558794915 672
1537558794915 673
1537558794915 674
1537558794916 675
1537558794916 676
1537558794916 677
1537558794916 678
1537558794916 679
1537558794916 680
1537558794916 681
1537558794916 682
1537558794916 683
1537558794916 684
1537558794916 685
1537558794916 686
1537558794916 687
1537558794916 688
1537558794916 689
1537558794916 690
1537558794916 691
1537558794916 692
1537558794916 693
1537558794916 694
1537558794916 695
1537558794916 696
1537558794916 697
1537558794916 698
1537558794916 699
1537558794916 700
1537558794916 701
1537558794916 702
1537558794916 703
1537558794916 704
1537558794916 705
1537558794916 706
1537558794916 707
1537558794916 708
1537558794916 709
1537558794916 710
1537558794916 711
1537558794916 712
1537558794916 713
1537558794916 714
1537558794916 715
1537558794916 716
1537558794916 717
1537558794916 718
1537558794916 719
1537558794916 720
1537558794916 721
1537558794916 722
1537558794916 723
1537558794916 724
1537558794916 725
1537558794916 726
1537558794916 727
1537558794916 728
1537558794916 729
1537558794916 730
1537558794916 731
1537558794916 732
1537558794916 733
1537558794916 734
1537558794916 735
1537558794916 736
1537558794916 737
1537558794916 738
1537558794916 739
1537558794916 740
1537558794916 741
1537558794916 742
1537558794916 743
1537558794916 744
1537558794916 745
1537558794916 746
1537558794916 747
1537558794916 748
1537558794916 749
1537558794916 750
1537558794916 751
1537558794916 752
1537558794917 753
1537558794917 754
1537558794917 755
1537558794917 756
1537558794917 757
1537558794917 758
1537558794917 759
1537558794917 760
1537558794917 761
1537558794917 762
1537558794917 763
1537558794917 764
1537558794917 765
1537558794917 766
1537558794917 767
1537558794917 768
1537558794917 769
1537558794917 770
1537558794917 771
1537558794917 772
1537558794917 773
1537558794917 774
1537558794917 775
1537558794917 776
1537558794917 777
1537558794917 778
1537558794917 779
1537558794917 780
1537558794917 781
1537558794917 782
1537558794917 783
1537558794917 784
1537558794917 785
1537558794917 786
1537558794917 787
1537558794917 788
1537558794917 789
1537558794917 790
1537558794917 791
1537558794917 792
1537558794917 793
1537558794917 794
1537558794917 795
1537558794917 796
1537558794917 797
1537558794917 798
1537558794917 799
1537558794917 800
1537558794917 801
1537558794917 802
1537558794917 803
1537558794917 804
1537558794917 805
1537558794917 806
1537558794917 807
1537558794917 808
1537558794917 809
1537558794917 810
1537558794917 811
1537558794917 812
1537558794917 813
1537558794917 814
1537558794917 815
1537558794917 816
1537558794917 817
1537558794917 818
1537558794917 819
1537558794917 820
1537558794917 821
1537558794917 822
1537558794917 823
1537558794917 824
1537558794917 825
1537558794918 826
1537558794918 827
1537558794918 828
1537558794918 829
1537558794918 830
1537558794918 831
1537558794918 832
1537558794918 833
1537558794918 834
1537558794918 835
1537558794918 836
1537558794918 837
1537558794918 838
1537558794918 839
1537558794918 840
1537558794918 841
1537558794918 842
1537558794918 843
1537558794918 844
1537558794918 845
1537558794918 846
1537558794918 847
1537558794918 848
1537558794918 849
1537558794918 850
1537558794918 851
1537558794918 852
1537558794918 853
1537558794918 854
1537558794918 855
1537558794918 856
1537558794918 857
1537558794918 858
1537558794918 859
1537558794918 860
1537558794918 861
1537558794918 862
1537558794918 863
1537558794918 864
1537558794918 865
1537558794918 866
1537558794918 867
1537558794918 868
namespace StreamingServer
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using Akka.Actor;
using Akka.Configuration;
using Akka.IO;
using Akka.Streams;
using Akka.Streams.Csv;
using Akka.Streams.Csv.Dsl;
using Akka.Streams.Dsl;
/// <summary>
/// Startup class to initialise parts of the application
/// </summary>
public class Startup
{
private static Config configServer = ConfigurationFactory.ParseString(@"
akka {
actor {
provider = remote
}
remote {
dot-netty.tcp {
port = 9001 #bound to a specific port
hostname = localhost
}
}
}
");
/// <summary>
/// Initialise and start the server actor system.
/// </summary>
public static void StartServerActorSystem()
{
var system = StreamingServerActorRefs.System = ActorSystem.Create("StreamingServerActorSystem", configServer);
var mat = system.Materializer();
var dataSource = Source.ActorRef<Tuple<DateTime, double>>(5000, OverflowStrategy.Fail);
var formatter = new CsvFormatter(',', '"', '\\', "\r\n", CsvQuotingStyle.Required);
var flow = Flow.Create<Tuple<DateTime, double>>()
.Select(t => formatter
.ToCsv(new List<string> {
new DateTimeOffset(t.Item1).ToUnixTimeMilliseconds().ToString(),
t.Item2.ToString(CultureInfo.InvariantCulture)
})
);
var file = new FileInfo("rawdata.csv");
var fileSink = FileIO.ToFile(file);
var dataSourceActor = StreamingServerActorRefs.DataSourceActor = dataSource.Via(flow).To(fileSink).Run(mat);
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<LangVersion>Latest</LangVersion>
<CodeAnalysisRuleSet>..\MindReader.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\Debug\netcoreapp2.1\StreamingServer.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<LangVersion>Latest</LangVersion>
<CodeAnalysisRuleSet>..\MindReader.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Akka.Streams" Version="1.3.9" />
<PackageReference Include="Akka" Version="1.3.9" />
<PackageReference Include="Akka.Remote" Version="1.3.9" />
<PackageReference Include="Akka.Logger.NLog" Version="1.3.3" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="2.6.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.9.0" />
<PackageReference Include="Akka.Streams.Csv" Version="0.1.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Actors\" />
</ItemGroup>
</Project>
using Akka.Actor;
namespace StreamingServer
{
internal static class StreamingServerActorRefs
{
internal static ActorSystem System;
internal static IActorRef DataSourceActor;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment