1
1
using System ;
2
2
using Amazon ;
3
3
using Amazon . DynamoDBv2 ;
4
+ using Amazon . Kinesis ;
4
5
using Amazon . Runtime ;
5
6
using Amazon . SQS ;
6
7
using Microsoft . Extensions . Logging ;
@@ -15,28 +16,55 @@ public static class ServiceCollectionExtensions
15
16
{
16
17
public static WorkflowOptions UseAwsSimpleQueueService ( this WorkflowOptions options , AWSCredentials credentials , AmazonSQSConfig config , string queuesPrefix = "workflowcore" )
17
18
{
18
- options . UseQueueProvider ( sp => new SQSQueueProvider ( credentials , config , sp . GetService < ILoggerFactory > ( ) , queuesPrefix ) ) ;
19
+ var sqsClient = new AmazonSQSClient ( credentials , config ) ;
20
+ return options . UseAwsSimpleQueueServiceWithProvisionedClient ( sqsClient , queuesPrefix ) ;
21
+ }
22
+
23
+ public static WorkflowOptions UseAwsSimpleQueueServiceWithProvisionedClient ( this WorkflowOptions options , AmazonSQSClient sqsClient , string queuesPrefix = "workflowcore" )
24
+ {
25
+ options . UseQueueProvider ( sp => new SQSQueueProvider ( sqsClient , sp . GetService < ILoggerFactory > ( ) , queuesPrefix ) ) ;
19
26
return options ;
20
27
}
21
28
22
29
public static WorkflowOptions UseAwsDynamoLocking ( this WorkflowOptions options , AWSCredentials credentials , AmazonDynamoDBConfig config , string tableName )
23
30
{
24
- options . UseDistributedLockManager ( sp => new DynamoLockProvider ( credentials , config , tableName , sp . GetService < ILoggerFactory > ( ) , sp . GetService < IDateTimeProvider > ( ) ) ) ;
31
+ var dbClient = new AmazonDynamoDBClient ( credentials , config ) ;
32
+ return options . UseAwsDynamoLockingWithProvisionedClient ( dbClient , tableName ) ;
33
+ }
34
+
35
+ public static WorkflowOptions UseAwsDynamoLockingWithProvisionedClient ( this WorkflowOptions options , AmazonDynamoDBClient dynamoClient , string tableName )
36
+ {
37
+ options . UseDistributedLockManager ( sp => new DynamoLockProvider ( dynamoClient , tableName , sp . GetService < ILoggerFactory > ( ) , sp . GetService < IDateTimeProvider > ( ) ) ) ;
25
38
return options ;
26
39
}
27
40
28
41
public static WorkflowOptions UseAwsDynamoPersistence ( this WorkflowOptions options , AWSCredentials credentials , AmazonDynamoDBConfig config , string tablePrefix )
29
42
{
30
- options . Services . AddTransient < IDynamoDbProvisioner > ( sp => new DynamoDbProvisioner ( credentials , config , tablePrefix , sp . GetService < ILoggerFactory > ( ) ) ) ;
31
- options . UsePersistence ( sp => new DynamoPersistenceProvider ( credentials , config , sp . GetService < IDynamoDbProvisioner > ( ) , tablePrefix , sp . GetService < ILoggerFactory > ( ) ) ) ;
43
+ var dbClient = new AmazonDynamoDBClient ( credentials , config ) ;
44
+ return options . UseAwsDynamoPersistenceWithProvisionedClient ( dbClient , tablePrefix ) ;
45
+ }
46
+
47
+ public static WorkflowOptions UseAwsDynamoPersistenceWithProvisionedClient ( this WorkflowOptions options , AmazonDynamoDBClient dynamoClient , string tablePrefix )
48
+ {
49
+ options . Services . AddTransient < IDynamoDbProvisioner > ( sp => new DynamoDbProvisioner ( dynamoClient , tablePrefix , sp . GetService < ILoggerFactory > ( ) ) ) ;
50
+ options . UsePersistence ( sp => new DynamoPersistenceProvider ( dynamoClient , sp . GetService < IDynamoDbProvisioner > ( ) , tablePrefix , sp . GetService < ILoggerFactory > ( ) ) ) ;
32
51
return options ;
33
52
}
34
53
35
54
public static WorkflowOptions UseAwsKinesis ( this WorkflowOptions options , AWSCredentials credentials , RegionEndpoint region , string appName , string streamName )
36
55
{
37
- options . Services . AddTransient < IKinesisTracker > ( sp => new KinesisTracker ( credentials , region , "workflowcore_kinesis" , sp . GetService < ILoggerFactory > ( ) ) ) ;
38
- options . Services . AddTransient < IKinesisStreamConsumer > ( sp => new KinesisStreamConsumer ( credentials , region , sp . GetService < IKinesisTracker > ( ) , sp . GetService < IDistributedLockProvider > ( ) , sp . GetService < ILoggerFactory > ( ) , sp . GetService < IDateTimeProvider > ( ) ) ) ;
39
- options . UseEventHub ( sp => new KinesisProvider ( credentials , region , appName , streamName , sp . GetService < IKinesisStreamConsumer > ( ) , sp . GetService < ILoggerFactory > ( ) ) ) ;
56
+ var kinesisClient = new AmazonKinesisClient ( credentials , region ) ;
57
+ var dynamoClient = new AmazonDynamoDBClient ( credentials , region ) ;
58
+
59
+ return options . UseAwsKinesisWithProvisionedClients ( kinesisClient , dynamoClient , appName , streamName ) ;
60
+
61
+ }
62
+
63
+ public static WorkflowOptions UseAwsKinesisWithProvisionedClients ( this WorkflowOptions options , AmazonKinesisClient kinesisClient , AmazonDynamoDBClient dynamoDbClient , string appName , string streamName )
64
+ {
65
+ options . Services . AddTransient < IKinesisTracker > ( sp => new KinesisTracker ( dynamoDbClient , "workflowcore_kinesis" , sp . GetService < ILoggerFactory > ( ) ) ) ;
66
+ options . Services . AddTransient < IKinesisStreamConsumer > ( sp => new KinesisStreamConsumer ( kinesisClient , sp . GetService < IKinesisTracker > ( ) , sp . GetService < IDistributedLockProvider > ( ) , sp . GetService < ILoggerFactory > ( ) , sp . GetService < IDateTimeProvider > ( ) ) ) ;
67
+ options . UseEventHub ( sp => new KinesisProvider ( kinesisClient , appName , streamName , sp . GetService < IKinesisStreamConsumer > ( ) , sp . GetService < ILoggerFactory > ( ) ) ) ;
40
68
return options ;
41
69
}
42
70
}
0 commit comments