├── .dockerignore
├── .gitignore
├── LICENSE
├── Oxygen.sln
├── README.md
├── sample
├── Basic.yaml
├── ClienActorSample
│ ├── ClienActorSample.csproj
│ ├── HelloActorService.cs
│ ├── HelloRepository.cs
│ ├── IHelloRepository.cs
│ └── MyActor.cs
├── Client
│ ├── .dockerignore
│ ├── CallServiceImpl.cs
│ ├── Client.csproj
│ ├── Dockerfile
│ ├── Dockerfile.Debug
│ ├── Program.cs
│ ├── Properties
│ │ └── launchSettings.json
│ └── start.bat
├── DaprActorProxyGenerator
│ ├── DaprActorProxyGenerator.csproj
│ └── DefaultSourceGenerator.cs
├── RemoteInterface
│ ├── ICallService.cs
│ ├── IHelloService.cs
│ └── RemoteInterface.csproj
├── RunBasic.bat
├── Server
│ ├── .dockerignore
│ ├── Dockerfile
│ ├── Dockerfile.Debug
│ ├── HelloEventHandler.cs
│ ├── HelloServiceImpl.cs
│ ├── Program.cs
│ ├── Properties
│ │ └── launchSettings.json
│ ├── Server.csproj
│ └── start.bat
├── start-dapr-debug.yaml
├── start-dapr.yaml
├── start-sample.bat
├── stop-sample.bat
└── test
│ └── start-dapr-debug.yaml
└── src
├── Oxygen.Client
├── Oxygen.Client.ServerProxyFactory
│ ├── Implements
│ │ ├── EventBus.cs
│ │ ├── ServiceProxyFactory.cs
│ │ └── StateManager.cs
│ ├── Interface
│ │ ├── IEventBus.cs
│ │ ├── IServiceProxyFactory.cs
│ │ └── IStateManager.cs
│ ├── Module.cs
│ └── Oxygen.Client.ServerProxyFactory.csproj
└── Oxygen.Client.ServerSymbol
│ ├── Actors
│ └── ActorSendDto.cs
│ ├── Events
│ ├── DefaultEventHandlerResponse.cs
│ ├── EventHandleRequest.cs
│ ├── EventHandleRequestData.cs
│ ├── EventHandleRequestExtension.cs
│ ├── EventHandlerAttribute.cs
│ ├── IActorService.cs
│ └── IEventHandler.cs
│ ├── FuncType.cs
│ ├── Oxygen.Client.ServerSymbol.csproj
│ ├── RemoteFuncAttribute.cs
│ ├── RemoteServiceAttribute.cs
│ └── Store
│ └── StateStore.cs
├── Oxygen.Mesh
└── Oxygen.Mesh.Dapr
│ ├── ActorServiceFactory.cs
│ ├── BaseActorService.cs
│ ├── BasicActor.cs
│ ├── Model
│ └── ActorStateModel.cs
│ ├── Oxygen.Mesh.Dapr.csproj
│ ├── OxygenActorStartup.cs
│ └── ProxyCodeGeneratorTemplate.cs
├── Oxygen.Server
└── Oxygen.Server.Kestrel
│ ├── Implements
│ ├── BaseRequestDelegate.cs
│ ├── HttpMessageHandler.cs
│ ├── KestrelServerHandler.cs
│ ├── OxygenApplication.cs
│ ├── OxygenHostService.cs
│ ├── OxygenStartup.cs
│ ├── RequestDelegate.cs
│ └── RequestDelegateFactory.cs
│ ├── Interface
│ ├── IMessageHandler.cs
│ ├── IServerHandler.cs
│ ├── MessageType.cs
│ └── Model
│ │ └── SubscribeModel.cs
│ ├── Module.cs
│ └── Oxygen.Server.Kestrel.csproj
└── Oxygen
├── Oxygen.Common
├── DaprConfig.cs
├── Implements
│ ├── ConsoleLog.cs
│ ├── HttpContextExtension.cs
│ ├── InProcessEventBus
│ │ ├── InProcessEventBusManager.cs
│ │ ├── InProcessPipline.cs
│ │ ├── InProcessPiplineFactory.cs
│ │ └── SubscribeInProcessFactory.cs
│ ├── JsonConverters
│ │ └── TextJsonConverter.cs
│ ├── OxygenHttpContextWapper.cs
│ ├── OxygenIocContainer.cs
│ ├── ReflectionHelper.cs
│ └── SerializeImpl.cs
├── Interface
│ ├── IInProcessEventBus.cs
│ ├── ILogger.cs
│ ├── ISerialize.cs
│ └── ISubscribeInProcessFactory.cs
├── Module.cs
├── Oxygen.Common.csproj
└── Properties
│ └── launchSettings.json
├── Oxygen.IocModule
├── ContainerBuilderExtension.cs
└── Oxygen.IocModule.csproj
└── Oxygen.ProxyGenerator
├── Implements
├── LocalMethodAopProvider.cs
├── RemoteDispatchProxy.cs
├── RemoteMessageSender.cs
├── RemoteMessageSenderDelegate.cs
└── RemoteProxyGenerator.cs
├── Interface
├── IRemoteMessageSender.cs
├── IRemoteMessageSenderDelegate.cs
└── SendType.cs
├── Module.cs
└── Oxygen.ProxyGenerator.csproj
/.dockerignore:
--------------------------------------------------------------------------------
1 | **/.classpath
2 | **/.dockerignore
3 | **/.env
4 | **/.git
5 | **/.gitignore
6 | **/.project
7 | **/.settings
8 | **/.toolstarget
9 | **/.vs
10 | **/.vscode
11 | **/*.*proj.user
12 | **/*.dbmdl
13 | **/*.jfm
14 | **/azds.yaml
15 | **/bin
16 | **/charts
17 | **/docker-compose*
18 | **/Dockerfile*
19 | **/node_modules
20 | **/npm-debug.log
21 | **/obj
22 | **/secrets.dev.yaml
23 | **/values.dev.yaml
24 | LICENSE
25 | README.md
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。
3 | ################################################################################
4 |
5 | .vs
6 | */bin
7 | */obj
8 | *\pub
9 | bin
10 | Debug
11 | Release
12 | obj
13 | *.user
14 | /nugetpack
15 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 sd797994
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Oxygen.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30413.136
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{53585DF5-6F35-488D-B2D9-43E58F77D9B9}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Oxygen", "Oxygen", "{45771243-E9BA-4190-89A5-61C65D8AA4C9}"
9 | EndProject
10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Oxygen.Client", "Oxygen.Client", "{968ADFFE-171A-41DD-909B-B2861A30A9AF}"
11 | EndProject
12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Oxygen.Server", "Oxygen.Server", "{CAD0B964-AD48-4C63-A8F0-6E1BED350BA8}"
13 | EndProject
14 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Oxygen.Mesh", "Oxygen.Mesh", "{540472F6-CDDB-4E09-886E-BE16EEC65A00}"
15 | EndProject
16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{F8BAEF85-9B04-4D46-9E57-52DF40CC1185}"
17 | EndProject
18 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oxygen.Server.Kestrel", "src\Oxygen.Server\Oxygen.Server.Kestrel\Oxygen.Server.Kestrel.csproj", "{838884C4-2D6C-4AF6-8EED-EE27947B7FE2}"
19 | EndProject
20 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oxygen.Common", "src\Oxygen\Oxygen.Common\Oxygen.Common.csproj", "{716437F1-0715-4D6A-8F39-03DDADFDF3A1}"
21 | EndProject
22 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oxygen.ProxyGenerator", "src\Oxygen\Oxygen.ProxyGenerator\Oxygen.ProxyGenerator.csproj", "{E4A9406E-C07D-477C-A1A9-52586725B25B}"
23 | EndProject
24 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oxygen.Client.ServerProxyFactory", "src\Oxygen.Client\Oxygen.Client.ServerProxyFactory\Oxygen.Client.ServerProxyFactory.csproj", "{BB642028-45C9-438F-BAE4-A22E582359C1}"
25 | EndProject
26 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oxygen.Client.ServerSymbol", "src\Oxygen.Client\Oxygen.Client.ServerSymbol\Oxygen.Client.ServerSymbol.csproj", "{58D8475D-C23D-4B4B-ABE0-32E3199FCBD0}"
27 | EndProject
28 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oxygen.Mesh.Dapr", "src\Oxygen.Mesh\Oxygen.Mesh.Dapr\Oxygen.Mesh.Dapr.csproj", "{F4748E0B-C033-4293-BCB1-7370A55BB02D}"
29 | EndProject
30 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RemoteInterface", "sample\RemoteInterface\RemoteInterface.csproj", "{B6E9A444-7A28-4964-83E5-F84CC1F6E945}"
31 | EndProject
32 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "sample\Client\Client.csproj", "{3FB24A03-E88D-4FBC-B601-555D59389931}"
33 | EndProject
34 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Server", "sample\Server\Server.csproj", "{6C5E0E28-5B9B-4AB9-A122-27DF9F4C2333}"
35 | EndProject
36 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Oxygen.IocModule", "src\Oxygen\Oxygen.IocModule\Oxygen.IocModule.csproj", "{5BE04D5E-F3C2-4043-A472-D1CE61C795A6}"
37 | EndProject
38 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DaprActorProxyGenerator", "sample\DaprActorProxyGenerator\DaprActorProxyGenerator.csproj", "{6B9F0D86-B745-4203-97C1-1E59CCFE2FD7}"
39 | EndProject
40 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClienActorSample", "sample\ClienActorSample\ClienActorSample.csproj", "{DACFCFEB-B304-4A46-80DB-BE34048E3F1A}"
41 | EndProject
42 | Global
43 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
44 | Debug|Any CPU = Debug|Any CPU
45 | Release|Any CPU = Release|Any CPU
46 | EndGlobalSection
47 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
48 | {838884C4-2D6C-4AF6-8EED-EE27947B7FE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49 | {838884C4-2D6C-4AF6-8EED-EE27947B7FE2}.Debug|Any CPU.Build.0 = Debug|Any CPU
50 | {838884C4-2D6C-4AF6-8EED-EE27947B7FE2}.Release|Any CPU.ActiveCfg = Release|Any CPU
51 | {838884C4-2D6C-4AF6-8EED-EE27947B7FE2}.Release|Any CPU.Build.0 = Release|Any CPU
52 | {716437F1-0715-4D6A-8F39-03DDADFDF3A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53 | {716437F1-0715-4D6A-8F39-03DDADFDF3A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
54 | {716437F1-0715-4D6A-8F39-03DDADFDF3A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
55 | {716437F1-0715-4D6A-8F39-03DDADFDF3A1}.Release|Any CPU.Build.0 = Release|Any CPU
56 | {E4A9406E-C07D-477C-A1A9-52586725B25B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57 | {E4A9406E-C07D-477C-A1A9-52586725B25B}.Debug|Any CPU.Build.0 = Debug|Any CPU
58 | {E4A9406E-C07D-477C-A1A9-52586725B25B}.Release|Any CPU.ActiveCfg = Release|Any CPU
59 | {E4A9406E-C07D-477C-A1A9-52586725B25B}.Release|Any CPU.Build.0 = Release|Any CPU
60 | {BB642028-45C9-438F-BAE4-A22E582359C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
61 | {BB642028-45C9-438F-BAE4-A22E582359C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
62 | {BB642028-45C9-438F-BAE4-A22E582359C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
63 | {BB642028-45C9-438F-BAE4-A22E582359C1}.Release|Any CPU.Build.0 = Release|Any CPU
64 | {58D8475D-C23D-4B4B-ABE0-32E3199FCBD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
65 | {58D8475D-C23D-4B4B-ABE0-32E3199FCBD0}.Debug|Any CPU.Build.0 = Debug|Any CPU
66 | {58D8475D-C23D-4B4B-ABE0-32E3199FCBD0}.Release|Any CPU.ActiveCfg = Release|Any CPU
67 | {58D8475D-C23D-4B4B-ABE0-32E3199FCBD0}.Release|Any CPU.Build.0 = Release|Any CPU
68 | {F4748E0B-C033-4293-BCB1-7370A55BB02D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
69 | {F4748E0B-C033-4293-BCB1-7370A55BB02D}.Debug|Any CPU.Build.0 = Debug|Any CPU
70 | {F4748E0B-C033-4293-BCB1-7370A55BB02D}.Release|Any CPU.ActiveCfg = Release|Any CPU
71 | {F4748E0B-C033-4293-BCB1-7370A55BB02D}.Release|Any CPU.Build.0 = Release|Any CPU
72 | {B6E9A444-7A28-4964-83E5-F84CC1F6E945}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
73 | {B6E9A444-7A28-4964-83E5-F84CC1F6E945}.Debug|Any CPU.Build.0 = Debug|Any CPU
74 | {B6E9A444-7A28-4964-83E5-F84CC1F6E945}.Release|Any CPU.ActiveCfg = Release|Any CPU
75 | {B6E9A444-7A28-4964-83E5-F84CC1F6E945}.Release|Any CPU.Build.0 = Release|Any CPU
76 | {3FB24A03-E88D-4FBC-B601-555D59389931}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
77 | {3FB24A03-E88D-4FBC-B601-555D59389931}.Debug|Any CPU.Build.0 = Debug|Any CPU
78 | {3FB24A03-E88D-4FBC-B601-555D59389931}.Release|Any CPU.ActiveCfg = Release|Any CPU
79 | {3FB24A03-E88D-4FBC-B601-555D59389931}.Release|Any CPU.Build.0 = Release|Any CPU
80 | {6C5E0E28-5B9B-4AB9-A122-27DF9F4C2333}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
81 | {6C5E0E28-5B9B-4AB9-A122-27DF9F4C2333}.Debug|Any CPU.Build.0 = Debug|Any CPU
82 | {6C5E0E28-5B9B-4AB9-A122-27DF9F4C2333}.Release|Any CPU.ActiveCfg = Release|Any CPU
83 | {6C5E0E28-5B9B-4AB9-A122-27DF9F4C2333}.Release|Any CPU.Build.0 = Release|Any CPU
84 | {5BE04D5E-F3C2-4043-A472-D1CE61C795A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
85 | {5BE04D5E-F3C2-4043-A472-D1CE61C795A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
86 | {5BE04D5E-F3C2-4043-A472-D1CE61C795A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
87 | {5BE04D5E-F3C2-4043-A472-D1CE61C795A6}.Release|Any CPU.Build.0 = Release|Any CPU
88 | {6B9F0D86-B745-4203-97C1-1E59CCFE2FD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
89 | {6B9F0D86-B745-4203-97C1-1E59CCFE2FD7}.Debug|Any CPU.Build.0 = Debug|Any CPU
90 | {6B9F0D86-B745-4203-97C1-1E59CCFE2FD7}.Release|Any CPU.ActiveCfg = Release|Any CPU
91 | {6B9F0D86-B745-4203-97C1-1E59CCFE2FD7}.Release|Any CPU.Build.0 = Release|Any CPU
92 | {DACFCFEB-B304-4A46-80DB-BE34048E3F1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
93 | {DACFCFEB-B304-4A46-80DB-BE34048E3F1A}.Debug|Any CPU.Build.0 = Debug|Any CPU
94 | {DACFCFEB-B304-4A46-80DB-BE34048E3F1A}.Release|Any CPU.ActiveCfg = Release|Any CPU
95 | {DACFCFEB-B304-4A46-80DB-BE34048E3F1A}.Release|Any CPU.Build.0 = Release|Any CPU
96 | EndGlobalSection
97 | GlobalSection(SolutionProperties) = preSolution
98 | HideSolutionNode = FALSE
99 | EndGlobalSection
100 | GlobalSection(NestedProjects) = preSolution
101 | {45771243-E9BA-4190-89A5-61C65D8AA4C9} = {53585DF5-6F35-488D-B2D9-43E58F77D9B9}
102 | {968ADFFE-171A-41DD-909B-B2861A30A9AF} = {53585DF5-6F35-488D-B2D9-43E58F77D9B9}
103 | {CAD0B964-AD48-4C63-A8F0-6E1BED350BA8} = {53585DF5-6F35-488D-B2D9-43E58F77D9B9}
104 | {540472F6-CDDB-4E09-886E-BE16EEC65A00} = {53585DF5-6F35-488D-B2D9-43E58F77D9B9}
105 | {838884C4-2D6C-4AF6-8EED-EE27947B7FE2} = {CAD0B964-AD48-4C63-A8F0-6E1BED350BA8}
106 | {716437F1-0715-4D6A-8F39-03DDADFDF3A1} = {45771243-E9BA-4190-89A5-61C65D8AA4C9}
107 | {E4A9406E-C07D-477C-A1A9-52586725B25B} = {45771243-E9BA-4190-89A5-61C65D8AA4C9}
108 | {BB642028-45C9-438F-BAE4-A22E582359C1} = {968ADFFE-171A-41DD-909B-B2861A30A9AF}
109 | {58D8475D-C23D-4B4B-ABE0-32E3199FCBD0} = {968ADFFE-171A-41DD-909B-B2861A30A9AF}
110 | {F4748E0B-C033-4293-BCB1-7370A55BB02D} = {540472F6-CDDB-4E09-886E-BE16EEC65A00}
111 | {B6E9A444-7A28-4964-83E5-F84CC1F6E945} = {F8BAEF85-9B04-4D46-9E57-52DF40CC1185}
112 | {3FB24A03-E88D-4FBC-B601-555D59389931} = {F8BAEF85-9B04-4D46-9E57-52DF40CC1185}
113 | {6C5E0E28-5B9B-4AB9-A122-27DF9F4C2333} = {F8BAEF85-9B04-4D46-9E57-52DF40CC1185}
114 | {5BE04D5E-F3C2-4043-A472-D1CE61C795A6} = {45771243-E9BA-4190-89A5-61C65D8AA4C9}
115 | {6B9F0D86-B745-4203-97C1-1E59CCFE2FD7} = {F8BAEF85-9B04-4D46-9E57-52DF40CC1185}
116 | {DACFCFEB-B304-4A46-80DB-BE34048E3F1A} = {F8BAEF85-9B04-4D46-9E57-52DF40CC1185}
117 | EndGlobalSection
118 | GlobalSection(ExtensibilityGlobals) = postSolution
119 | SolutionGuid = {B216A394-6D76-4027-9E89-9E4882077CC4}
120 | EndGlobalSection
121 | EndGlobal
122 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Oxygen-Dapr
2 | 一款基于dapr的.netRPC封装。统一了请求编程模型(服务调用/事件/状态&Actor)和服务(基于kestrel router/eventhandle/actorservice提供直接对应用服务的访问)
3 |
--------------------------------------------------------------------------------
/sample/Basic.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: postgres
5 | namespace: infrastructure
6 | spec:
7 | selector:
8 | matchLabels:
9 | app: postgres
10 | replicas: 1
11 | template:
12 | metadata:
13 | labels:
14 | app: postgres
15 | spec:
16 | containers:
17 | - name: postgres
18 | image: postgres:latest
19 | imagePullPolicy: IfNotPresent
20 | ports:
21 | - containerPort: 5432
22 | name: web
23 | env:
24 | - name: POSTGRES_PASSWORD
25 | value: "Mytestpwd#123"
26 | - name: TZ
27 | value: "Asia/Shanghai"
28 | ---
29 | apiVersion: v1
30 | kind: Service
31 | metadata:
32 | name: postgres
33 | namespace: infrastructure
34 | spec:
35 | type: NodePort
36 | selector:
37 | app: postgres
38 | ports:
39 | - protocol: TCP
40 | port: 5432
41 | targetPort: 5432
42 | nodePort: 30432
43 | name: tcp-postgres
44 | ---
45 | apiVersion: apps/v1
46 | kind: Deployment
47 | metadata:
48 | name: redis
49 | namespace: infrastructure
50 | spec:
51 | selector:
52 | matchLabels:
53 | app: redis
54 | replicas: 1
55 | template:
56 | metadata:
57 | labels:
58 | app: redis
59 | spec:
60 | containers:
61 | - name: redis
62 | image: redis:latest
63 | imagePullPolicy: IfNotPresent
64 | ports:
65 | - containerPort: 6379
66 | name: web
67 | env:
68 | - name: TZ
69 | value: "Asia/Shanghai"
70 | ---
71 | apiVersion: v1
72 | kind: Service
73 | metadata:
74 | name: redis
75 | namespace: infrastructure
76 | spec:
77 | selector:
78 | app: redis
79 | ports:
80 | - protocol: TCP
81 | port: 6379
82 | targetPort: 6379
83 | name: tcp-redis
84 | ---
85 | apiVersion: dapr.io/v1alpha1
86 | kind: Component
87 | metadata:
88 | name: statestore
89 | namespace: default
90 | spec:
91 | type: state.redis
92 | version: v1
93 | metadata:
94 | - name: actorStateStore
95 | value: "true"
96 | - name: redisHost
97 | value: redis.infrastructure.svc.cluster.local:6379
98 | - name: keyPrefix
99 | value: none
100 | ---
101 | apiVersion: dapr.io/v1alpha1
102 | kind: Component
103 | metadata:
104 | name: pubsub
105 | namespace: default
106 | spec:
107 | type: pubsub.redis
108 | version: v1
109 | metadata:
110 | - name: redisHost
111 | value: redis.infrastructure.svc.cluster.local:6379
--------------------------------------------------------------------------------
/sample/ClienActorSample/ClienActorSample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/sample/ClienActorSample/HelloActorService.cs:
--------------------------------------------------------------------------------
1 | using Autofac;
2 | using Microsoft.Extensions.Logging;
3 | using Oxygen.Client.ServerProxyFactory.Interface;
4 | using Oxygen.Mesh.Dapr;
5 | using Oxygen.Mesh.Dapr.Model;
6 | using RemoteInterface;
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Linq;
10 | using System.Text;
11 | using System.Threading.Tasks;
12 |
13 | namespace ClienActorSample
14 | {
15 | public class HelloActorService : BaseActorService, IHelloActorService
16 | {
17 | private readonly ILogger logger;
18 | private readonly IStateManager stateManager;
19 | private readonly IHelloRepository helloRepository;
20 | public HelloActorService(ILogger logger, IStateManager stateManager, IHelloRepository helloRepository)
21 | {
22 | this.logger = logger;
23 | this.stateManager = stateManager;
24 | this.helloRepository = helloRepository;
25 | }
26 | public async Task GetUserInfoByActor(ActorInputDto input)
27 | {
28 | if (ActorData == null)
29 | ActorData = await helloRepository.GetData();
30 | ActorData.Index++;
31 | if (ActorData.Index == 10)
32 | ActorData.DeleteModel();
33 | return await Task.FromResult(new OutDto() { Word = $"hello {input.Name},your id is {ActorData.Index}" });
34 | }
35 |
36 | public override async Task SaveData(MyActor data, ILifetimeScope scope)
37 | {
38 | if (data != null)
39 | await helloRepository.SaveData(data);
40 | await Task.CompletedTask;
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/sample/ClienActorSample/HelloRepository.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace ClienActorSample
8 | {
9 | public class HelloRepository : IHelloRepository
10 | {
11 | public Guid? Id { get; set; }
12 | public HelloRepository()
13 | {
14 | Id = Id ?? Guid.NewGuid();
15 | }
16 | public async Task SaveData(MyActor actor)
17 | {
18 | Console.WriteLine($"仓储实例ID:{Id},持久化对象:{actor?.Index}");
19 | await Task.CompletedTask;
20 | }
21 |
22 | public async Task GetData()
23 | {
24 | return await Task.FromResult(new MyActor() { Index = 0, AutoSave = true });
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/sample/ClienActorSample/IHelloRepository.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace ClienActorSample
8 | {
9 | public interface IHelloRepository
10 | {
11 | Task GetData();
12 | Task SaveData(MyActor actor);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/sample/ClienActorSample/MyActor.cs:
--------------------------------------------------------------------------------
1 | using Oxygen.Mesh.Dapr.Model;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace ClienActorSample
9 | {
10 | public record MyActor : ActorStateModel
11 | {
12 | public int Index { get; set; }
13 | public override bool AutoSave { get; set; }
14 | public override int ReminderSeconds { get => 1; }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/sample/Client/.dockerignore:
--------------------------------------------------------------------------------
1 | *.yaml
2 | *.bat
3 | *.sh
--------------------------------------------------------------------------------
/sample/Client/CallServiceImpl.cs:
--------------------------------------------------------------------------------
1 | using Autofac;
2 | using Dapr.Actors;
3 | using Dapr.Actors.Client;
4 | using Microsoft.Extensions.Logging;
5 | using Oxygen.Client.ServerProxyFactory.Interface;
6 | using Oxygen.Common.Interface;
7 | using Oxygen.Mesh.Dapr;
8 | using Oxygen.Mesh.Dapr.Model;
9 | using RemoteInterface;
10 | using System;
11 | using System.Collections.Concurrent;
12 | using System.Collections.Generic;
13 | using System.Diagnostics;
14 | using System.IO;
15 | using System.Linq;
16 | using System.Net.Http;
17 | using System.Reflection;
18 | using System.Text;
19 | using System.Text.Json;
20 | using System.Text.Json.Serialization;
21 | using System.Threading;
22 | using System.Threading.Tasks;
23 |
24 | namespace Client
25 | {
26 | public class CallServiceImpl : ICallService
27 | {
28 | private readonly IServiceProxyFactory serviceProxyFactory;
29 | private readonly IEventBus eventBus;
30 | private readonly IStateManager stateManager;
31 | private readonly ISerialize serialize;
32 | public CallServiceImpl(IServiceProxyFactory serviceProxyFactory, ISerialize serialize, IEventBus eventBus, IStateManager stateManager)
33 | {
34 | this.serviceProxyFactory = serviceProxyFactory;
35 | this.eventBus = eventBus;
36 | this.stateManager = stateManager;
37 | this.serialize = serialize;
38 | }
39 | public async Task RemoteCallTest(InputDto input)
40 | {
41 | var helloService = serviceProxyFactory.CreateProxy();
42 | var test = await helloService.GetHtml();
43 | var helloactorService = serviceProxyFactory.CreateActorProxy();
44 | await stateManager.SetState(new TestStateDto("mykey", true));
45 | var getState = await stateManager.GetState(new TestStateDto("mykey"));
46 | var delState = await stateManager.DelState(new TestStateDto("mykey"));
47 | var invokeresult = await helloService.GetUserInfo(new InputDto() { name = "xiaoming" });
48 | var invokenoinputresult = await helloService.Test();
49 | var eventresult = await eventBus.SendEvent("test", new TestEventDto() { myword = "abc" });
50 | var actorresult = await helloactorService.GetUserInfoByActor(new ActorInputDto() { Name = "xiaoming", ActorId = "1" });
51 | return new InputDto() { name = $"RPC无参调用成功,回调:{JsonSerializer.Serialize(invokenoinputresult)},RPC有参调用成功,回调:{JsonSerializer.Serialize(invokeresult)},事件发送{(eventresult != null ? "成功" : "失败")},状态写入成功,值:{getState},actor调用成功,回调:{JsonSerializer.Serialize(actorresult)}" };
52 | }
53 | public async Task MultipleTest(MultipleTestInput input)
54 | {
55 | var max = input.Times <= 0 ? 1 : input.Times;
56 | var succ = 0;
57 | var fail = 0;
58 | var _event = new AutoResetEvent(false);
59 | ConcurrentBag times = new ConcurrentBag();
60 | Stopwatch _sw = new Stopwatch();
61 | _sw.Start();
62 | Parallel.For(0, max, async i =>
63 | {
64 | var helloService = serviceProxyFactory.CreateProxy();
65 | Stopwatch _sw_item = new Stopwatch();
66 | _sw_item.Start();
67 | var invokeresult = await helloService.GetUserInfo(new InputDto() { name = "小明" });
68 | var eventresult = await eventBus.SendEvent("test", new TestEventDto() { myword = "abc" });
69 | _sw_item.Stop();
70 | if (invokeresult != null)
71 | {
72 | Interlocked.Increment(ref succ);
73 | times.Add(_sw_item.ElapsedMilliseconds);
74 | }
75 | else
76 | Interlocked.Increment(ref fail);
77 | if (succ + fail == max)
78 | _event.Set();
79 | });
80 | _event.WaitOne();
81 | _sw.Stop();
82 | return await Task.FromResult(new MultipleTestOutput()
83 | {
84 | AllTimes = input.Times,
85 | SuccTimes = succ,
86 | FailTimes = fail,
87 | CustTimes = _sw.ElapsedMilliseconds,
88 | Detail = string.Join(",", times.Where(x => x > 100).ToList())
89 | });
90 | }
91 | }
92 |
93 | }
--------------------------------------------------------------------------------
/sample/Client/Client.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | enable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/sample/Client/Dockerfile:
--------------------------------------------------------------------------------
1 | from mcr.microsoft.com/dotnet/aspnet:8.0
2 | WORKDIR /app
3 | COPY /pub .
4 | RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
5 | ENTRYPOINT ["dotnet", "Client.dll"]
--------------------------------------------------------------------------------
/sample/Client/Dockerfile.Debug:
--------------------------------------------------------------------------------
1 | from mcr.microsoft.com/dotnet/aspnet:8.0
2 | WORKDIR /app
3 | RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
4 | ENTRYPOINT ["dotnet", "Client.dll"]
--------------------------------------------------------------------------------
/sample/Client/Program.cs:
--------------------------------------------------------------------------------
1 | using Autofac;
2 | using Autofac.Extensions.DependencyInjection;
3 | using ClienActorSample;
4 | using Client;
5 | using Microsoft.Extensions.Hosting;
6 | using Oxygen.IocModule;
7 | using Oxygen.Mesh.Dapr;
8 | using Oxygen.Server.Kestrel.Implements;
9 | using RemoteInterface;
10 |
11 | var builder = OxygenApplication.CreateBuilder(config =>
12 | {
13 | config.Port = 80;
14 | config.PubSubCompentName = "pubsub";
15 | config.StateStoreCompentName = "statestore";
16 | config.TracingHeaders = "Authentication";
17 | config.UseCors = true;
18 | });
19 | OxygenActorStartup.ConfigureServices(builder.Services);
20 | builder.Host.ConfigureContainer(builder =>
21 | {
22 | //注入oxygen依赖
23 | builder.RegisterOxygenModule();
24 | //注入测试demo
25 | builder.RegisterType().As().InstancePerLifetimeScope();
26 | builder.RegisterType().As().InstancePerLifetimeScope();
27 | builder.RegisterType().As().InstancePerLifetimeScope();
28 | });
29 | builder.Services.AddAutofac();
30 | builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
31 | var app = builder.Build();
32 | OxygenActorStartup.Configure(app, app.Services);
33 | await app.RunAsync();
--------------------------------------------------------------------------------
/sample/Client/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "iisSettings": {
3 | "windowsAuthentication": false,
4 | "anonymousAuthentication": true,
5 | "iisExpress": {
6 | "applicationUrl": "http://localhost:51918/",
7 | "sslPort": 44384
8 | }
9 | },
10 | "profiles": {
11 | "IIS Express": {
12 | "commandName": "IISExpress",
13 | "launchBrowser": true,
14 | "environmentVariables": {
15 | "ASPNETCORE_ENVIRONMENT": "Development"
16 | }
17 | },
18 | "Client": {
19 | "commandName": "Project",
20 | "launchBrowser": true,
21 | "environmentVariables": {
22 | "ASPNETCORE_ENVIRONMENT": "Development"
23 | },
24 | "applicationUrl": "https://localhost:5001;http://localhost:5000"
25 | }
26 | }
27 | }
--------------------------------------------------------------------------------
/sample/Client/start.bat:
--------------------------------------------------------------------------------
1 | dotnet publish -c release
2 | cd bin/release/netcoreapp3.1/publish/
3 | Client.exe
--------------------------------------------------------------------------------
/sample/DaprActorProxyGenerator/DaprActorProxyGenerator.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0
5 | $(GetTargetPathDependsOn);GetDependencyTargetPaths
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/sample/DaprActorProxyGenerator/DefaultSourceGenerator.cs:
--------------------------------------------------------------------------------
1 | using ClienActorSample;
2 | using Microsoft.CodeAnalysis;
3 | using Microsoft.CodeAnalysis.Text;
4 | using Oxygen.Mesh.Dapr.ActorProxyGenerator;
5 | using RemoteInterface;
6 | using System.Diagnostics;
7 | using System.Text;
8 |
9 | namespace DaprActorProxyGenerator
10 | {
11 | [Generator]
12 | public class DefaultSourceGenerator : ISourceGenerator
13 | {
14 | public void Execute(GeneratorExecutionContext context)
15 | {
16 | var proxylist = ProxyCodeGeneratorTemplate.GetTemplate();
17 | foreach (var item in proxylist)
18 | {
19 | context.AddSource(item.sourceName, SourceText.From(item.sourceCode, Encoding.UTF8));
20 | }
21 | }
22 |
23 | public void Initialize(GeneratorInitializationContext context)
24 | {
25 | Debugger.Launch();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/sample/RemoteInterface/ICallService.cs:
--------------------------------------------------------------------------------
1 | using Oxygen.Client.ServerSymbol;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Net.Http;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace RemoteInterface
9 | {
10 | [RemoteService("callservice", "call")]
11 | public interface ICallService
12 | {
13 | [RemoteFunc]
14 | Task RemoteCallTest(InputDto input);
15 | [RemoteFunc]
16 | Task MultipleTest(MultipleTestInput input);
17 | }
18 | public class MultipleTestInput
19 | {
20 | public int Times { get; set; }
21 | }
22 | public class MultipleTestOutput
23 | {
24 | public int AllTimes { get; set; }
25 | public int SuccTimes { get; set; }
26 | public int FailTimes { get; set; }
27 | public long CustTimes { get; set; }
28 | public string Detail { get; set; }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/sample/RemoteInterface/IHelloService.cs:
--------------------------------------------------------------------------------
1 | using Oxygen.Client.ServerSymbol;
2 | using Oxygen.Client.ServerSymbol.Actors;
3 | using Oxygen.Client.ServerSymbol.Events;
4 | using Oxygen.Client.ServerSymbol.Store;
5 | using Oxygen.Mesh.Dapr;
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 |
11 | namespace RemoteInterface
12 | {
13 | [RemoteService("testservice", "hello")]
14 | public interface IHelloService
15 | {
16 | [RemoteFunc(FuncType.Invoke)]
17 | Task GetUserInfo(InputDto input);
18 | [RemoteFunc(FuncType.Invoke)]
19 | Task GetState(InputDto input);
20 | [RemoteFunc(FuncType.Invoke)]
21 | Task Test();
22 | [RemoteFunc]
23 | Task GetHtml();
24 | }
25 | [RemoteService("testservice", "helloactor")]
26 | public interface IHelloActorService : IActorService
27 | {
28 | [RemoteFunc(FuncType.Actor)]
29 | Task GetUserInfoByActor(ActorInputDto input);
30 | }
31 | public class ActorInputDto : ActorSendDto
32 | {
33 | public string Name { get; set; }
34 | public override string ActorId { get; set; }
35 | }
36 | public class InputDto
37 | {
38 | public string name { get; set; }
39 | public int id { get; set; }
40 | public bool getbool { get; set; }
41 | }
42 | public class OutDto
43 | {
44 | public string Word { get; set; }
45 | }
46 | public class TestEventDto
47 | {
48 | public string myword { get; set; }
49 | }
50 | public class TestStateDto : StateStore
51 | {
52 | public TestStateDto(string key)
53 | {
54 | this.Key = key;
55 | }
56 | public TestStateDto(string key, object data)
57 | {
58 | this.Key = key;
59 | this.Data = data;
60 | this.TtlInSeconds = -1;//默认不设置超时时间
61 | }
62 | public override string Key { get; set; }
63 | public override object Data { get; set; }
64 | }
65 | public class MyTestStateContent
66 | {
67 | public Guid Id { get; set; }
68 | public string Name { get; set; }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/sample/RemoteInterface/RemoteInterface.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/sample/RunBasic.bat:
--------------------------------------------------------------------------------
1 | kubectl create ns infrastructure
2 | kubectl apply -f Basic.yaml
--------------------------------------------------------------------------------
/sample/Server/.dockerignore:
--------------------------------------------------------------------------------
1 | *.yaml
2 | *.bat
3 | *.sh
--------------------------------------------------------------------------------
/sample/Server/Dockerfile:
--------------------------------------------------------------------------------
1 | from mcr.microsoft.com/dotnet/aspnet:8.0
2 | WORKDIR /app
3 | COPY /pub .
4 | RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
5 | ENTRYPOINT ["dotnet", "Server.dll"]
--------------------------------------------------------------------------------
/sample/Server/Dockerfile.Debug:
--------------------------------------------------------------------------------
1 | from mcr.microsoft.com/dotnet/aspnet:8.0
2 | WORKDIR /app
3 | RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
4 | ENTRYPOINT ["dotnet", "Server.dll"]
--------------------------------------------------------------------------------
/sample/Server/HelloEventHandler.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.Logging;
2 | using Oxygen.Client.ServerSymbol;
3 | using Oxygen.Client.ServerSymbol.Events;
4 | using Oxygen.Server.Kestrel.Implements;
5 | using RemoteInterface;
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Text;
9 | using System.Text.Encodings.Web;
10 | using System.Text.Json;
11 | using System.Text.Unicode;
12 | using System.Threading.Tasks;
13 |
14 | namespace Server
15 | {
16 | public class HelloEventHandler : IEventHandler
17 | {
18 | private readonly ILogger logger;
19 | public HelloEventHandler(ILogger logger)
20 | {
21 | this.logger = logger;
22 | }
23 | [EventHandlerFunc("test")]
24 | public async Task SubscribeByUserInfoEvent(EventHandleRequest input)
25 | {
26 | logger.LogInformation($"订阅器收到消息:{JsonSerializer.Serialize(input.GetData(), new JsonSerializerOptions() { Encoder = JavaScriptEncoder.Create(UnicodeRanges.All) })}");
27 | return await Task.FromResult(DefaultEventHandlerResponse.Default());
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/sample/Server/HelloServiceImpl.cs:
--------------------------------------------------------------------------------
1 | using Autofac;
2 | using Microsoft.Extensions.Logging;
3 | using Oxygen.Client.ServerProxyFactory.Interface;
4 | using Oxygen.Mesh.Dapr;
5 | using Oxygen.Mesh.Dapr.Model;
6 | using RemoteInterface;
7 | using System;
8 | using System.Threading.Tasks;
9 |
10 | namespace Server
11 | {
12 | public class HelloServiceImpl : IHelloService
13 | {
14 | private readonly ILogger logger;
15 | private readonly IStateManager stateManager;
16 | public HelloServiceImpl(ILogger logger, IStateManager stateManager)
17 | {
18 | this.logger = logger;
19 | this.stateManager = stateManager;
20 | }
21 | public async Task GetUserInfo(InputDto input)
22 | {
23 | return await Task.FromResult(new OutDto() { Word = $"hello {input?.name}" });
24 | }
25 | public async Task GetState(InputDto input)
26 | {
27 | var state = await stateManager.GetState(new TestStateDto(input.name));
28 | return await Task.FromResult(new OutDto() { Word = state.ToString() });
29 | }
30 | public async Task Test()
31 | {
32 | return await Task.FromResult(new OutDto() { Word = "noinput" });
33 | }
34 |
35 | public async Task GetHtml()
36 | {
37 | HttpContextCurrent.GetCurrent().HttpContext.Response.Cookies.Append("aaa", "bbb");
38 | HttpContextCurrent.GetCurrent().HttpContext.Response.Redirect("http://www.baidu.com");
39 | return await Task.FromResult("");
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/sample/Server/Program.cs:
--------------------------------------------------------------------------------
1 | using Autofac;
2 | using Autofac.Extensions.DependencyInjection;
3 | using Microsoft.AspNetCore.Builder;
4 | using Microsoft.Extensions.Hosting;
5 | using Oxygen.Common.Implements;
6 | using Oxygen.IocModule;
7 | using Oxygen.Mesh.Dapr;
8 | using Oxygen.ProxyGenerator.Implements;
9 | using Oxygen.Server.Kestrel.Implements;
10 | using RemoteInterface;
11 | using Server;
12 | using System.Text.Json;
13 |
14 | var builder = OxygenApplication.CreateBuilder(config =>
15 | {
16 | config.Port = 80;
17 | config.PubSubCompentName = "pubsub";
18 | config.StateStoreCompentName = "statestore";
19 | config.TracingHeaders = "Authentication";
20 | });
21 | OxygenActorStartup.ConfigureServices(builder.Services);
22 | builder.Host.ConfigureContainer(builder =>
23 | {
24 | //注入oxygen依赖
25 | builder.RegisterOxygenModule();
26 | //注入测试demo
27 | builder.RegisterType().As().InstancePerLifetimeScope();
28 | builder.RegisterType().As().InstancePerLifetimeScope();
29 | });
30 | builder.Services.AddAutofac();
31 | builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
32 | //注册全局拦截器
33 | LocalMethodAopProvider.RegisterPipelineHandler((methodctx) => {
34 | HttpContextCurrent.SetCurrent(methodctx);
35 | }, async (obj, methodctx) =>
36 | {
37 | if (obj != null)
38 | Console.WriteLine($"这里是方法前拦截器,拦截到参数:{JsonSerializer.Serialize(obj)}");
39 | await Task.CompletedTask;
40 | var s = HttpContextCurrent.GetCurrent();
41 |
42 | }, async (result) =>
43 | {
44 | Console.WriteLine($"这里是方法后拦截器,拦截到方法结果:{JsonSerializer.Serialize(result)}");
45 | var s = HttpContextCurrent.GetCurrent();
46 | await Task.CompletedTask;
47 | }, async (exp) =>
48 | {
49 | Console.WriteLine($"这里是方法异常拦截器,拦截到异常:{exp.Message}");
50 | return await Task.FromResult(new { Message = exp.Message });
51 | });
52 | var app = builder.Build();
53 | OxygenActorStartup.Configure(app, app.Services);
54 | await app.RunAsync();
55 | public static class HttpContextCurrent
56 | {
57 | private static AsyncLocal currentcontext = new AsyncLocal();
58 | internal static void SetCurrent(OxygenHttpContextWapper httpContextWapper)
59 | {
60 | if (currentcontext.Value == null)
61 | currentcontext.Value = httpContextWapper;
62 | }
63 | internal static OxygenHttpContextWapper GetCurrent()
64 | {
65 | return currentcontext.Value;
66 | }
67 | }
--------------------------------------------------------------------------------
/sample/Server/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "profiles": {
3 | "Server": {
4 | "commandName": "Project"
5 | },
6 | "Docker": {
7 | "commandName": "Docker"
8 | }
9 | }
10 | }
--------------------------------------------------------------------------------
/sample/Server/Server.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | Linux
7 | ..\..
8 | enable
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/sample/Server/start.bat:
--------------------------------------------------------------------------------
1 | dotnet publish -c release
2 | cd bin/release/netcoreapp3.1/publish/
3 | Server.exe
--------------------------------------------------------------------------------
/sample/start-dapr-debug.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: oxygen-dapr-sample-client
5 | labels:
6 | app: oxygen-dapr-sample-client
7 | spec:
8 | replicas: 1
9 | selector:
10 | matchLabels:
11 | app: oxygen-dapr-sample-client
12 | minReadySeconds: 5
13 | strategy:
14 | type: RollingUpdate
15 | rollingUpdate:
16 | maxUnavailable: 1
17 | maxSurge: 1
18 | template:
19 | metadata:
20 | labels:
21 | app: oxygen-dapr-sample-client
22 | annotations:
23 | dapr.io/enabled: "true"
24 | dapr.io/app-id: "callservice"
25 | dapr.io/app-port: "80"
26 | spec:
27 | containers:
28 | - name: web
29 | image: oxygen-dapr-sample-client:debug
30 | imagePullPolicy: Never
31 | env:
32 | - name: Logging__Console__FormatterName
33 | value: ""
34 | ports:
35 | - containerPort: 80
36 | volumeMounts:
37 | - mountPath: /app
38 | name: v1
39 | - mountPath: /remote_debugger:rw
40 | name: v2
41 | volumes:
42 | - name: v1
43 | hostPath:
44 | path: /run/desktop/mnt/host/e/dotnet_project/Oxygen-Dapr/sample/Client/bin/Debug/net8.0
45 | - name: v2
46 | hostPath:
47 | path: /run/desktop/mnt/host/c/Users/Administrator/vsdbg/vs2017u5
48 | ---
49 | apiVersion: apps/v1
50 | kind: Deployment
51 | metadata:
52 | name: oxygen-dapr-sample-server
53 | labels:
54 | app: oxygen-dapr-sample-server
55 | spec:
56 | replicas: 1
57 | selector:
58 | matchLabels:
59 | app: oxygen-dapr-sample-server
60 | minReadySeconds: 5
61 | strategy:
62 | type: RollingUpdate
63 | rollingUpdate:
64 | maxUnavailable: 1
65 | maxSurge: 1
66 | template:
67 | metadata:
68 | labels:
69 | app: oxygen-dapr-sample-server
70 | annotations:
71 | dapr.io/enabled: "true"
72 | dapr.io/app-id: "testservice"
73 | dapr.io/app-port: "80"
74 | spec:
75 | containers:
76 | - name: web
77 | image: oxygen-dapr-sample-server:debug
78 | imagePullPolicy: Never
79 | env:
80 | - name: Logging__Console__FormatterName
81 | value: ""
82 | ports:
83 | - containerPort: 80
84 | volumeMounts:
85 | - mountPath: /app
86 | name: v1
87 | - mountPath: /remote_debugger:rw
88 | name: v2
89 | volumes:
90 | - name: v1
91 | hostPath:
92 | path: /run/desktop/mnt/host/e/dotnet_project/Oxygen-Dapr/sample/Server/bin/Debug/net8.0
93 | - name: v2
94 | hostPath:
95 | path: /run/desktop/mnt/host/c/Users/Administrator/vsdbg/vs2017u5
96 | ---
97 | apiVersion: v1
98 | kind: Service
99 | metadata:
100 | name: oxygen-dapr-sample-server
101 | spec:
102 | selector:
103 | app: oxygen-dapr-sample-server
104 | ports:
105 | - protocol: TCP
106 | port: 80
107 | targetPort: 80
108 | ---
109 | apiVersion: v1
110 | kind: Service
111 | metadata:
112 | name: oxygen-dapr-sample-client
113 | spec:
114 | selector:
115 | app: oxygen-dapr-sample-client
116 | ports:
117 | - protocol: TCP
118 | port: 80
119 | targetPort: 80
120 | ---
121 | apiVersion: networking.k8s.io/v1
122 | kind: Ingress
123 | metadata:
124 | namespace: default
125 | name: oxygen-dapr
126 | annotations:
127 | kubernetes.io/ingress.class: "nginx"
128 | spec:
129 | rules:
130 | - host: api.oxygen-dapr.com
131 | http:
132 | paths:
133 | - path: /
134 | pathType: Prefix
135 | backend:
136 | service:
137 | name: oxygen-dapr-sample-client
138 | port:
139 | number: 80
--------------------------------------------------------------------------------
/sample/start-dapr.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: oxygen-dapr-sample-client
5 | labels:
6 | app: oxygen-dapr-sample-client
7 | spec:
8 | replicas: 1
9 | selector:
10 | matchLabels:
11 | app: oxygen-dapr-sample-client
12 | minReadySeconds: 5
13 | strategy:
14 | type: RollingUpdate
15 | rollingUpdate:
16 | maxUnavailable: 1
17 | maxSurge: 1
18 | template:
19 | metadata:
20 | labels:
21 | app: oxygen-dapr-sample-client
22 | annotations:
23 | dapr.io/enabled: "true"
24 | dapr.io/app-id: "callservice"
25 | dapr.io/app-port: "80"
26 | spec:
27 | containers:
28 | - name: web
29 | image: oxygen-dapr-sample-client:latest
30 | imagePullPolicy: Never
31 | env:
32 | - name: Logging__Console__FormatterName
33 | value: ""
34 | ports:
35 | - containerPort: 80
36 | ---
37 | apiVersion: apps/v1
38 | kind: Deployment
39 | metadata:
40 | name: oxygen-dapr-sample-server
41 | labels:
42 | app: oxygen-dapr-sample-server
43 | spec:
44 | replicas: 1
45 | selector:
46 | matchLabels:
47 | app: oxygen-dapr-sample-server
48 | minReadySeconds: 5
49 | strategy:
50 | type: RollingUpdate
51 | rollingUpdate:
52 | maxUnavailable: 1
53 | maxSurge: 1
54 | template:
55 | metadata:
56 | labels:
57 | app: oxygen-dapr-sample-server
58 | annotations:
59 | dapr.io/enabled: "true"
60 | dapr.io/app-id: "testservice"
61 | dapr.io/app-port: "80"
62 | spec:
63 | containers:
64 | - name: web
65 | image: oxygen-dapr-sample-server:latest
66 | env:
67 | - name: Logging__Console__FormatterName
68 | value: ""
69 | imagePullPolicy: Never
70 | ports:
71 | - containerPort: 80
72 | ---
73 | apiVersion: networking.k8s.io/v1
74 | kind: Ingress
75 | metadata:
76 | namespace: default
77 | name: oxygen-dapr
78 | annotations:
79 | kubernetes.io/ingress.class: "nginx"
80 | spec:
81 | rules:
82 | - host: api.oxygen-dapr.com
83 | http:
84 | paths:
85 | - path: /
86 | pathType: Prefix
87 | backend:
88 | service:
89 | name: oxygen-dapr-sample-client
90 | port:
91 | number: 80
--------------------------------------------------------------------------------
/sample/start-sample.bat:
--------------------------------------------------------------------------------
1 | kubectl delete -f start-dapr.yaml
2 | set /p mode=
3 | if %mode% == 1 (
4 | cd Client
5 | rd /S /Q pub
6 | dotnet clean
7 | dotnet publish -c Release -o pub
8 | docker build . -t oxygen-dapr-sample-client:latest
9 | cd ../Server
10 | rd /S /Q pub
11 | dotnet publish -c Release -o pub
12 | docker build . -t oxygen-dapr-sample-server:latest
13 | cd ../
14 | kubectl delete -f start-dapr.yaml
15 | kubectl apply -f start-dapr.yaml
16 | ) ^
17 | else (
18 | cd ../
19 | dotnet clean
20 | dotnet build Oxygen.sln
21 | cd sample/Client
22 | docker build . -t oxygen-dapr-sample-client:debug -f Dockerfile.Debug
23 | cd ../Server
24 | docker build . -t oxygen-dapr-sample-server:debug -f Dockerfile.Debug
25 | cd ../
26 | kubectl apply -f start-dapr-debug.yaml
27 | )
28 | docker system prune -f
29 | kubectl get po -w
--------------------------------------------------------------------------------
/sample/stop-sample.bat:
--------------------------------------------------------------------------------
1 | kubectl delete -f start-dapr.yaml
--------------------------------------------------------------------------------
/sample/test/start-dapr-debug.yaml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: oxygen-dapr-sample-test
5 | labels:
6 | app: oxygen-dapr-sample-test
7 | spec:
8 | replicas: 1
9 | selector:
10 | matchLabels:
11 | app: oxygen-dapr-sample-test
12 | minReadySeconds: 5
13 | strategy:
14 | type: RollingUpdate
15 | rollingUpdate:
16 | maxUnavailable: 1
17 | maxSurge: 1
18 | template:
19 | metadata:
20 | labels:
21 | app: oxygen-dapr-sample-test
22 | spec:
23 | containers:
24 | - name: web
25 | image: oxygen-dapr-sample-server:latest
26 | imagePullPolicy: Never
27 | ports:
28 | - containerPort: 80
29 | volumeMounts:
30 | - mountPath: /app
31 | name: v1
32 | # - mountPath: /remote_debugger:rw
33 | # name: v2
34 | # - mountPath: /root/.vs-debugger
35 | # name: v3
36 | volumes:
37 | - name: v1
38 | hostPath:
39 | path: /e/dotnet_project/Oxygen-Dapr/sample/Server/bin/Debug/netcoreapp3.1
40 | # - name: v2
41 | # hostPath:
42 | # path: /c/Users/Administrator/vsdbg/vs2017u5
43 | # - name: v3
44 | # hostPath:
45 | # path: /e/dockerdebugger/.vs-debugger
--------------------------------------------------------------------------------
/src/Oxygen.Client/Oxygen.Client.ServerProxyFactory/Implements/EventBus.cs:
--------------------------------------------------------------------------------
1 | using Oxygen.Client.ServerProxyFactory.Interface;
2 | using Oxygen.Client.ServerSymbol.Events;
3 | using Oxygen.Common;
4 | using Oxygen.ProxyGenerator.Interface;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 |
11 | namespace Oxygen.Client.ServerProxyFactory.Implements
12 | {
13 | public class EventBus : IEventBus
14 | {
15 | private readonly IRemoteMessageSender messageSender;
16 | public EventBus(IRemoteMessageSender messageSender)
17 | {
18 | this.messageSender = messageSender;
19 | }
20 | public async Task SendEvent(string topic, T input)
21 | {
22 | return await messageSender.SendMessage(DaprConfig.GetCurrent().PubSubCompentName, $"/{topic}", input, SendType.publish);
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/src/Oxygen.Client/Oxygen.Client.ServerProxyFactory/Implements/ServiceProxyFactory.cs:
--------------------------------------------------------------------------------
1 | using Oxygen.Client.ServerProxyFactory.Interface;
2 | using Oxygen.Client.ServerSymbol.Events;
3 | using Oxygen.Common.Implements;
4 | using Oxygen.ProxyGenerator.Interface;
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace Oxygen.Client.ServerProxyFactory.Implements
11 | {
12 | public class ServiceProxyFactory : IServiceProxyFactory
13 | {
14 | public T CreateProxy() where T : class
15 | {
16 | return OxygenIocContainer.Resolve();
17 | }
18 | public T CreateActorProxy() where T : class
19 | {
20 | return OxygenIocContainer.ResolveNamed($"{typeof(T).FullName}ActorProxy");
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Oxygen.Client/Oxygen.Client.ServerProxyFactory/Implements/StateManager.cs:
--------------------------------------------------------------------------------
1 | using Oxygen.Client.ServerProxyFactory.Interface;
2 | using Oxygen.Client.ServerSymbol.Events;
3 | using Oxygen.Client.ServerSymbol.Store;
4 | using Oxygen.Common;
5 | using Oxygen.ProxyGenerator.Interface;
6 | using System;
7 | using System.Collections.Generic;
8 | using System.Linq;
9 | using System.Text;
10 | using System.Threading.Tasks;
11 |
12 | namespace Oxygen.Client.ServerProxyFactory.Implements
13 | {
14 | public class StateManager : IStateManager
15 | {
16 | private readonly IRemoteMessageSender messageSender;
17 | public StateManager(IRemoteMessageSender messageSender)
18 | {
19 | this.messageSender = messageSender;
20 | }
21 | public async Task DelState(StateStore input)
22 | {
23 | return await messageSender.SendMessage(DaprConfig.GetCurrent().StateStoreCompentName, $"/{input.Key}", null, SendType.delState);
24 | }
25 | public async Task GetState(StateStore input) where T : new()
26 | {
27 | return await messageSender.SendMessage(DaprConfig.GetCurrent().StateStoreCompentName, $"/{input.Key}", null, SendType.getState);
28 | }
29 |
30 | public async Task