嗨,我正在尝试从事件中心接收消息。下面是我在 java spring 代码中完成的 appyaml 配置:
spring:
cloud:
azure:
eventhubs:
connection-string: ${EVENT_HUB_CONN:Endpoint=}
namespace: ${AZURE_EVENTHUBS_NAMESPACE:}
processor:
checkpoint-store:
account-name: ${AZURE_STORAGE_ACCOUNT_NAME:}
account-key: ${STORAGE_ACC_KEY:}
container-name: ${AZURE_STORAGE_CONTAINER_NAME:ccapiresiliencyservice}
stream:
bindings:
consume-in-0:
destination: ${AZURE_EVENTHUB_NAME:}
group: ${AZURE_EVENTHUB_CONSUMER_GROUP:}
eventhubs:
bindings:
consume-in-0:
consumer:
checkpoint:
mode: MANUAL
poller:
initial-delay: 0
fixed-delay: 1000
function:
definition: consume;
我已在 azure 中创建了事件中心和存储帐户,一切正常。
但是,一旦我在存储帐户中启用虚拟网络,我就开始在应用程序中收到错误。
我现在应该如何从应用程序的事件中心启用对我的存储帐户的访问。 我尝试过分配身份和角色,但目前似乎没有任何效果。
我应该如何启用从应用程序中的事件中心访问我的存储帐户?
您可以通过 Azure 虚拟机从启用了选定网络的事件中心访问存储帐户。
您需要创建虚拟机并将公共 IP 地址添加到您的存储帐户,如下所示:
传送门:
现在,您可以在 Azure 虚拟机中使用与 Java Spring 代码相同的配置文件:
spring:
cloud:
azure:
eventhubs:
connection-string: ${EVENT_HUB_CONN:Endpoint=}
namespace: ${AZURE_EVENTHUBS_NAMESPACE:}
processor:
checkpoint-store:
account-name: ${AZURE_STORAGE_ACCOUNT_NAME:}
account-key: ${STORAGE_ACC_KEY:}
container-name: ${AZURE_STORAGE_CONTAINER_NAME:ccapiresiliencyservice}
stream:
bindings:
consume-in-0:
destination: ${AZURE_EVENTHUB_NAME:}
group: ${AZURE_EVENTHUB_CONSUMER_GROUP:}
eventhubs:
bindings:
consume-in-0:
consumer:
checkpoint:
mode: MANUAL
poller:
initial-delay: 0
fixed-delay: 1000
function:
definition: consume;
我尝试使用示例 Python 代码从事件中心接收消息。
输出:
Received the event: "First event" from the partition with ID: "0"
Received the event: "Second event" from the partition with ID: "0"
Received the event: "Third event" from the partition with ID: "0"