无法从 GCP 数据流连接到 GCP Memorystore

Cannot connect to GCP Memorystore from GCP Dataflow

我正在尝试使用 GCP Memorystore 来处理 GCP Dataflow 上的事件流作业 运行 的会话 ID。尝试连接到 Memorystore 时作业因超时而失败:

redis.clients.jedis.exceptions.JedisConnectionException: Failed connecting to host 10.0.0.4:6379
    at redis.clients.jedis.Connection.connect(Connection.java:207)
    at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:101)
    at redis.clients.jedis.Connection.sendCommand(Connection.java:126)
    at redis.clients.jedis.Connection.sendCommand(Connection.java:117)
    at redis.clients.jedis.Jedis.get(Jedis.java:155)

我的 Memorystore 实例具有以下属性:

Version is 4.0
Authorized network is default-auto
Master is in us-central1-b. Replica is in us-central1-a.
Connection properties: IP address: 10.0.0.4, Port number: 6379 
> gcloud redis instances list --region us-central1
INSTANCE_NAME  VERSION    REGION       TIER         SIZE_GB  HOST      PORT  NETWORK       RESERVED_IP  STATUS  CREATE_TIME
memorystore    REDIS_4_0  us-central1  STANDARD_HA  1        10.0.0.4  6379  default-auto  10.0.0.0/29  READY   2019-07-15T11:43:14

我的 Dataflow 作业具有以下属性:

runner: org.apache.beam.runners.dataflow.DataflowRunner
zone: us-central1-b
network: default-auto
> gcloud dataflow jobs list   
JOB_ID                                    NAME                        TYPE       CREATION_TIME        STATE      REGION
2019-06-17_02_01_36-3308621933676080017   eventflow                   Streaming  2019-06-17 09:01:37  Running    us-central1

我的 "default" 网络无法使用,因为它是 Memorystore 不接受的旧版网络。我没能找到将默认网络从传统网络升级到自动网络的方法,并且不想删除现有的默认网络,因为这需要打乱生产服务。相反,我创建了一个自动类型的新网络 "default-auto",具有与默认网络相同的防火墙规则。我认为与我的数据流工作相关的是:

Name: default-auto-internal
Type: Ingress
Targets: Apply to all   
Filters: IP ranges: 10.0.0.0/20
Protocols/ports: 
  tcp:0-65535
  udp:0-65535
  icmp
Action: Allow
Priority: 65534

我可以使用 "telnet 10.0.0.4 6379" 从 Compute Engine 实例连接到 Memorystore。

我已经尝试过,但没有任何改变: - 将 Redis 库从 Jedis 2.9.3 切换到 Lettuce 5.1.7 - 删除并重新创建了 Memorystore 实例

Dataflow 是否应该无法连接到 Memorystore,还是我遗漏了什么?

想通了。我试图从直接从我的数据流作业的主要方法调用的代码连接到 Memorystore。从数据流步骤中的代码 运行ning 连接成功。其次(好吧,实际上更像是第 1002 个想法)这是有道理的,因为 main() 在驱动程序机器上 运行ning(在这种情况下是我的桌面),而数据流图的步骤将 运行在 GCP 上。我已经通过在我的 main() 中连接到 localhost:6379 上的 Memorystore 证实了这一理论。这是有效的,因为我在端口 6379 上有一个到 Memorystore 运行ning 的 SSH 隧道(使用 this trick)。