Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/dotnetcore/CAP
Browse files Browse the repository at this point in the history
  • Loading branch information
yang-xiaodong committed Oct 9, 2024
2 parents 0e5fa19 + 899e4a2 commit d2f25eb
Show file tree
Hide file tree
Showing 36 changed files with 978 additions and 604 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ public void ShowTime2(DateTime datetime)
}

```
`ShowTime1` and `ShowTime2` will be called one after another because all received messages are processed linear.
You can change that behaviour to set `UseDispatchingPerGroup` true.
`ShowTime1` and `ShowTime2` will be called at the same time.

BTW, You can specify the default group name in the configuration:

Expand Down
2 changes: 1 addition & 1 deletion README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public void ShowTime2(DateTime datetime)

```

`ShowTime1``ShowTime2` 处于不同的组,他们在默认情况下被线性的接连调用,你可以通过设置`UseDispatchingPerGroup`为true来使两者互不影响的同时调用
`ShowTime1``ShowTime2` 将被同时调用

PS,你可以通过下面的方式来指定默认的消费者组名称:

Expand Down
2 changes: 1 addition & 1 deletion build/version.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<VersionMajor>8</VersionMajor>
<VersionMinor>2</VersionMinor>
<VersionMinor>3</VersionMinor>
<VersionPatch>0</VersionPatch>
<VersionQuality></VersionQuality>
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
Expand Down
80 changes: 80 additions & 0 deletions docs/content/user-guide/en/monitoring/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ services.AddCap(x =>

```

## UseK8sDiscovery Configuration

This configuration option is used to configure the Dashboard/Nodes to list every K8s `service` by default. If this is set to `True` then only services with the `dotnetcore.cap.visibility: show` label will be listed. More information on labels will be found on the **Kubernetes Labels Configuration** section.

* ShowOnlyExplicitVisibleNodes

> Default :false

```cs
services.AddCap(x =>
{
// ...
x.UseK8sDiscovery(opt=>{
opt.ShowOnlyExplicitVisibleNodes = true;
});
});
```

The component will automatically detect whether it is inside the cluster. If it is inside the cluster, the Pod must be granted Kubernetes Api permissions. Refer to the next section.

## Assign Pod Access to Kubernetes Api
Expand Down Expand Up @@ -90,6 +109,67 @@ spec:
targetPort: 80
```

From version `8.3.0` and onwards you can use a `Role` instead of `ClusterRole` to allow discovery of services only inside the namespace that the dashboard is running. Kubernetes Roles has limited jurisdiction inside the namespace. In the above example just remove ClusterRole and ClusterRoleBinding and instead use the following:

```
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: ns-svc-reader
rules:
- apiGroups: [""]
resources: ["services"]
verbs: ["get", "watch", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: read-pods
subjects:
- kind: ServiceAccount
name: api-access
namespace: default
roleRef:
kind: ClusterRole
name: ns-svc-reader
apiGroup: rbac.authorization.k8s.io
```

## Kubernetes Labels Configuration

The list of Nodes showed in the dashboard can be controlled by adding labels to the to your kubernetes services.


- `dotnetcore.cap.visibility` label is used to show or hide a service from the list.

> Allowed Values: show | hide
> Examples: `dotnetcore.cap.visibility: show` or `dotnetcore.cap.visibility: hide`
By default every k8s service is listed with the first port found in the service. However if more ports are present on the service you can select the wanted by using the following labels:

- `dotnetcore.cap.portName` label is used to filter the wanted port of the service.

> Allowed Values: string
> Examples: `dotnetcore.cap.portName: grpc` or `dotnetcore.cap.portName: http`
If not found any port with the given name, it will try to match the next label portIndex

- `dotnetcore.cap.portIndex` label is used to filter the wanted port of the service. This filter is taken into consideration only if no label portName is set or a non matching portName is set.

> Allowed Values: number represented as string ex: '2' or '14'
> Examples: `dotnetcore.cap.portIndex: '1'` or `dotnetcore.cap.portIndex: '3'`
If the provided index is outside of bounds then it will fallback to the first port (index:0)





## Using Dashboard Standalone

You can use the Dashboard standalone without configuring CAP, in this case, the Dashboard can be deployed as a separate Pod in the Kubernetes cluster just for data viewing. The service to be viewed no longer needs to configure the `cap.UseK8sDiscovery()` option.
Expand Down
1 change: 1 addition & 0 deletions docs/content/user-guide/en/transport/rabbitmq.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ VirtualHost | Broker virtual host | string | /
Port | Port | int | -1
ExchangeName | Default exchange name | string | cap.default.topic
QueueArguments | Extra queue `x-arguments` | QueueArgumentsOptions | N/A
QueueOptions | Change Options for created queue | QueueRabbitOptions | { Durable=true, Exclusive=false, AutoDelete=false }
ConnectionFactoryOptions | RabbitMQClient native connection options | ConnectionFactory | N/A
CustomHeadersBuilder | Custom subscribe headers | See the blow | N/A
PublishConfirms | Enable [publish confirms](https://www.rabbitmq.com/confirms.html#publisher-confirms) | bool | false
Expand Down
78 changes: 78 additions & 0 deletions docs/content/user-guide/zh/monitoring/kubernetes.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ services.AddCap(x =>

```

## 使用K8sDiscovery配置

此配置选项用于配置仪表板/节点以默认列出每个 K8s `service` 。如果将此设置为 `true`,则只会列出带有`dotnetcore.cap.visibility: show` 标签的服务。有关标签的更多信息可以在 **Kubernetes 标签配置** 部分找到。

* ShowOnlyExplicitVisibleNodes

> 默认值:false

```cs
services.AddCap(x =>
{
// ...
x.UseK8sDiscovery(opt=>{
opt.ShowOnlyExplicitVisibleNodes = true;
});
});
```

组件将会自动检测是否处于集群内部,如果处于集群内部在需要赋予Pod Kubernetes Api 的权限。参考下一章节。

## 分配 Pod 访问 Kubernetes Api
Expand Down Expand Up @@ -90,6 +109,65 @@ spec:
targetPort: 80
```

从版本 `8.3.0` 及更高版本,您可以使用 `Role` 而不是 `ClusterRole`,以允许仅在仪表板运行的命名空间内发现服务。 Kubernetes 角色在命名空间内拥有有限的管辖权。在上面的示例中,只需删除 ClusterRole 和 ClusterRoleBinding 并改为使用以下内容

```
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: ns-svc-reader
rules:
- apiGroups: [""]
resources: ["services"]
verbs: ["get", "watch", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: read-pods
subjects:
- kind: ServiceAccount
name: api-access
namespace: default
roleRef:
kind: ClusterRole
name: ns-svc-reader
apiGroup: rbac.authorization.k8s.io
```

## Kubernetes 标签配置

可以通过向 kubernetes 服务添加标签来控制仪表板中显示的节点列表。


- `dotnetcore.cap.visibility` 标签用于显示或隐藏列表中的服务。

> 可能的值: show | hide
> 示例: `dotnetcore.cap.visibility: show` or `dotnetcore.cap.visibility: hide`
默认情况下,每个 k8s 服务都会列出该服务中找到的第一个端口。但是,如果服务上存在更多端口,您可以使用以下标签选择所需的端口:

- `dotnetcore.cap.portName` 标签用于过滤需要的服务端口。

> 可能的值: string
> 示例: `dotnetcore.cap.portName: grpc` or `dotnetcore.cap.portName: http`
If not found any port with the given name, it will try to match the next label portIndex

- `dotnetcore.cap.portIndex` 标签用于过滤需要的服务端口。 仅当未设置标签 portName 或设置不匹配的 portName 时,才会考虑此过滤器。

> 可能的值: 数字表示为字符串 ex: '2' or '14'
> 示例: `dotnetcore.cap.portIndex: '1'` or `dotnetcore.cap.portIndex: '3'`
如果提供的索引超出范围,那么它将回退到第一个端口(索引:0)



## 独立使用 Dashboard

你可以独立使用 Dashboard 而不需要配置CAP,此时相当于 Dashboard 可作为单独的 Pod 部署到 Kubernetes 集群中仅用作查看数据,待查看的服务不再需要配置 `cap.UseK8sDiscovery()` 配置项。
Expand Down
1 change: 1 addition & 0 deletions docs/content/user-guide/zh/transport/rabbitmq.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ VirtualHost | 虚拟主机 | string | /
Port | 端口号 | int | -1
ExchangeName | CAP默认Exchange名称 | string | cap.default.topic
QueueArguments | 队列额外参数 x-arguments | QueueArgumentsOptions | N/A
QueueOptions | 更改已创建队列的选项 | QueueRabbitOptions | { Durable=true, Exclusive=false, AutoDelete=false }
ConnectionFactoryOptions | RabbitMQClient原生参数 | ConnectionFactory | N/A
CustomHeadersBuilder | 订阅者自定义头信息 | 见下文 | N/A
PublishConfirms | 是否启用[发布确认](https://www.rabbitmq.com/confirms.html#publisher-confirms) | bool | false
Expand Down
4 changes: 2 additions & 2 deletions src/DotNetCore.CAP.AmazonSQS/DotNetCore.CAP.AmazonSQS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="3.7.300.24" />
<PackageReference Include="AWSSDK.SQS" Version="3.7.300.24" />
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="3.7.400.25" />
<PackageReference Include="AWSSDK.SQS" Version="3.7.400.25" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<None Remove="System.Linq.Async" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.17.0" />
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.18.1" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="KubernetesClient" Version="12.1.1" />
<PackageReference Include="KubernetesClient" Version="15.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DotNetCore.CAP.Dashboard\DotNetCore.CAP.Dashboard.csproj" />
Expand Down
7 changes: 7 additions & 0 deletions src/DotNetCore.CAP.Dashboard.K8s/K8sDiscoveryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ public class K8sDiscoveryOptions
public K8sDiscoveryOptions()
{
K8SClientConfig = KubernetesClientConfiguration.BuildDefaultConfig();
ShowOnlyExplicitVisibleNodes = true;
}

public KubernetesClientConfiguration K8SClientConfig { get; set; }

/// <summary>
/// If this is set to TRUE will make all nodes hidden by default. Only kubernetes services
/// with label "dotnetcore.cap.visibility:show" will be listed in the nodes section.
/// </summary>
public bool ShowOnlyExplicitVisibleNodes { get; set; }
}
Loading

0 comments on commit d2f25eb

Please sign in to comment.