Skip to content

Commit 4f0bd4e

Browse files
author
Arshia Ghafoori
committed
Clean code up, migrate to netstandard2.0, add nuget package props
1 parent 29fde7e commit 4f0bd4e

22 files changed

+274
-624
lines changed

README.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
## How to use
66

7-
OrleansCassandraUtils is Orleans 2.0 compatible.
7+
OrleansCassandraUtils is Orleans 3.x compatible.
88

9-
To set it up, you first need a working Cassandra DB. Create a new keyspace and run the `InitializeOrleansDatabase.cql` script on it. Note that unlike the ADO.Net provider, you can't put data from multiple clusters into one database/keyspace. You **must** create a new keyspace for each cluster.
9+
To set it up, you first need a working Cassandra DB. Create a new keyspace and run the `InitializeOrleansDatabase.cql` script on it. Note that unlike the ADO.Net provider, you can't put data from multiple clusters into one database/keyspace. You must create a new keyspace for each cluster.
1010

1111
OrleansCassandraUtils uses a custom connection string format not unlike SQL Server connection strings. The parameters (case-insensitive) are as follows:
1212

@@ -23,41 +23,41 @@ Then, setup your silo as follows:
2323

2424
### Grain storage
2525

26-
```
27-
new SiloHostBuilder().AddCassandraGrainStorageAsDefault((CassandraGrainStorageOptions o) =>
26+
```csharp
27+
siloBuilder.AddCassandraGrainStorageAsDefault((CassandraGrainStorageOptions o) =>
2828
{
2929
o.ConnctionString = myConnectionString;
3030
o.AddSerializationProvider(1, new MyCustomSerializationProvider());
3131
})
3232
```
3333

34-
You'll notice the `AddSerializationProvider` call above is unfamiliar. This is an optional feature you can use to provide your own serialization provider, either based on existing providers in Orleans or a new one altogether. You may add up to 127 providers, each with a unique code between 0 and 126. These codes must not change during the entire lifetime of a cluster, as the codes are stored alongside the data and then used to decide which deserializer to use when reading data back from the database. If you don't provide any custom serializers, Orleans' default serializer will be used. Beware however that the default serializer is **not** version-tolerant and you **will** break your entire DB if you make a change to any grain state classes. To implement a custom serializer, simply implement the `OrleansCassandraUtils.Persistence.IStorageSerializationProvider` interface.
34+
You'll notice the `AddSerializationProvider` call above is unfamiliar. This is an optional feature you can use to provide your own serialization provider, either based on existing providers in Orleans or a new one altogether. You may add up to 127 providers, each with a unique code between 0 and 126. These codes must not change during the entire lifetime of a cluster, as the codes are stored alongside the data and then used to decide which deserializer to use when reading data back from the database. If you don't provide any custom serializers, Orleans' default serializer will be used. Beware however that the default serializer is not version-tolerant and you *will* break your entire DB if you make a change to any grain state classes. To implement a custom serializer, simply implement the `OrleansCassandraUtils.Persistence.IStorageSerializationProvider` interface.
3535

36-
It's also worth mentioning that all grain state is serialized as binary data, since I find XML and JSON to be very inefficient, space- and perfomance-wise ([see](http://geekswithblogs.net/LeonidGaneline/archive/2015/05/06/serializers-in-.net.-v.2.aspx) [here](https://auth0.com/blog/beating-json-performance-with-protobuf/) for example). If you need text serialization, you can turn the resulting string into a UTF-8 byte sequence, though I would recommend against this approach. I prefer [Bond](https://github.com/Microsoft/bond), but you should also check out [Protobuf](https://developers.google.com/protocol-buffers/docs/overview).
36+
It's also worth mentioning that all grain state is serialized as binary data, since I find XML and JSON to be very inefficient, space- and perfomance-wise ([see](http://geekswithblogs.net/LeonidGaneline/archive/2015/05/06/serializers-in-.net.-v.2.aspx) [here](https://auth0.com/blog/beating-json-performance-with-protobuf/) for example). If you need text serialization, you can turn the resulting string into a UTF-8 byte sequence. I prefer [Bond](https://github.com/Microsoft/bond), but you can also use [Protobuf](https://developers.google.com/protocol-buffers/docs/overview).
3737

3838
### Clustering
3939

4040
On the silo side:
41-
```
42-
new SiloHostBuilder().UseCassandraClustering((CassandraClusteringOptions o) =>
41+
```csharp
42+
siloBuilder.UseCassandraClustering((CassandraClusteringOptions o) =>
4343
{
4444
o.ConnectionString = myConnectionString;
4545
})
4646
```
4747

4848
and on the client side:
4949

50-
```
51-
new ClientBuilder().UseCassandraClustering((CassandraClusteringOptions o) =>
50+
```csharp
51+
clientBuilder.UseCassandraClustering((CassandraClusteringOptions o) =>
5252
{
5353
o.ConnectionString = myConnectionString;
5454
})
5555
```
5656

5757
### Reminders
5858

59-
```
60-
new SiloHostBuilder().UseCassandraReminderService((CassandraClusteringOptions o) =>
59+
```csharp
60+
siloBuilder.UseCassandraReminderService((CassandraClusteringOptions o) =>
6161
{
6262
o.ConnectionString = myConnectionString;
6363
})
@@ -67,7 +67,7 @@ new SiloHostBuilder().UseCassandraReminderService((CassandraClusteringOptions o)
6767

6868
Cassandra clusters can be a good place to store your non-grain data as well. OrleansCassandraUtils provides the `OrleansCassandraUtils.Utils.CassandraSessionFactory` class, which you may use to acquire a Cassandra session and make custom queries against your cluster as follows:
6969

70-
```
70+
```csharp
7171
var session = await CassandraSessionFactory.CreateSession(myConnectionString);
7272
var queryResults = await Session.ExecuteAsync(new SimpleStatement("select * from my_table"));
7373
```

src/Directory.Build.props

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project>
2+
<PropertyGroup>
3+
<OrleansPackageVersion>3.4.0</OrleansPackageVersion>
4+
</PropertyGroup>
5+
</Project>

src/OrleansCassandraUtils.sln

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27428.2015
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31129.286
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrleansCassandraUtils", "OrleansCassandraUtils\OrleansCassandraUtils.csproj", "{31DE8494-D9F1-4812-A877-23621437693D}"
77
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{4515FA20-C8E4-435F-8694-BD94B3FA4D56}"
9+
ProjectSection(SolutionItems) = preProject
10+
Directory.Build.props = Directory.Build.props
11+
EndProjectSection
12+
EndProject
813
Global
914
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1015
Debug|Any CPU = Debug|Any CPU

src/OrleansCassandraUtils/Clustering/CassandraClusteringOptions.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
7-
namespace OrleansCassandraUtils.Clustering
1+
namespace OrleansCassandraUtils.Clustering
82
{
93
public class CassandraClusteringOptions
104
{

src/OrleansCassandraUtils/Clustering/CassandraClusteringTable.cs

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
using Orleans;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43
using System.Linq;
5-
using System.Text;
4+
using System.Net;
65
using System.Threading.Tasks;
7-
using Orleans.Runtime;
8-
using Orleans.Runtime.Configuration;
9-
using Orleans.Messaging;
106
using Cassandra;
11-
using OrleansCassandraUtils.Utils;
12-
using System.Net;
137
using Microsoft.Extensions.Options;
8+
using Orleans;
9+
using Orleans.Runtime;
10+
using OrleansCassandraUtils.Utils;
1411

1512
namespace OrleansCassandraUtils.Clustering
1613
{

src/OrleansCassandraUtils/Clustering/CassandraGatewayListProvider.cs

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
using Cassandra;
2-
using Microsoft.Extensions.Logging;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Net;
4+
using System.Threading.Tasks;
5+
using Cassandra;
36
using Microsoft.Extensions.Options;
47
using Orleans.Configuration;
58
using Orleans.Messaging;
69
using Orleans.Runtime;
7-
using Orleans.Runtime.Configuration;
810
using OrleansCassandraUtils.Utils;
9-
using System;
10-
using System.Collections.Generic;
11-
using System.Linq;
12-
using System.Net;
13-
using System.Text;
14-
using System.Threading.Tasks;
1511

1612
namespace OrleansCassandraUtils.Clustering
1713
{

0 commit comments

Comments
 (0)