java事件的接收_使用 Java 從 Azure 事件中樞傳送或接收事件 (最新) - Azure Event Hubs | Microsoft Docs...

使用 Java 將事件傳送至 Azure 事件中樞或從中接收事件 (azure-messaging-eventhubs)Use Java to send events to or receive events from Azure Event Hubs (azure-messaging-eventhubs)

06/23/2020

本文內容

本快速入門說明如何使用 azure-messaging-eventhubs Java 套件,來傳送事件至事件中樞和從事件中樞接收事件。This quickstart shows how to send events to and receive events from an event hub using the azure-messaging-eventhubs Java package.

重要

本快速入門使用新的 azure-messaging-eventhubs 套件。This quickstart uses the new azure-messaging-eventhubs package. 如需使用舊有 azure-eventhubs 和 azure-eventhubs-eph 套件的快速入門,請參閱使用 azure-eventhubs 和 azure-eventhubs-eph 傳送和接收事件。For a quickstart that uses the old azure-eventhubs and azure-eventhubs-eph packages, see Send and receive events using azure-eventhubs and azure-eventhubs-eph.

必要條件Prerequisites

如果您對 Azure 事件中樞並不熟悉,在進行此快速入門之前,請先參閱事件中樞概述。If you're new to Azure Event Hubs, see Event Hubs overview before you do this quickstart.

若要完成本快速入門,您必須符合下列必要條件:To complete this quickstart, you need the following prerequisites:

Microsoft Azure 訂用帳戶。Microsoft Azure subscription. 若要使用 Azure 服務 (包括 Azure 事件中樞),您需要訂用帳戶。To use Azure services, including Azure Event Hubs, you need a subscription. 如果您沒有現有的 Azure 帳戶,您可以申請免費試用,或是在建立帳戶時使用 MSDN 訂閱者權益。If you don't have an existing Azure account, you can sign up for a free trial or use your MSDN subscriber benefits when you create an account.

Java 開發環境。A Java development environment. 本快速入門使用 Eclipse。This quickstart uses Eclipse. 需要含第 8 版或更新版本的 Java 開發套件 (JDK)。Java Development Kit (JDK) with version 8 or above is required.

建立事件中樞命名空間和事件中樞。Create an Event Hubs namespace and an event hub. 第一個步驟是使用 Azure 入口網站來建立「事件中樞」類型的命名空間,然後取得您應用程式與「事件中樞」進行通訊所需的管理認證。The first step is to use the Azure portal to create a namespace of type Event Hubs, and obtain the management credentials your application needs to communicate with the event hub. 若要建立命名空間和事件中樞,請依照這篇文章中的程序操作。To create a namespace and an event hub, follow the procedure in this article. 然後,依照下列文章中的指示,取得事件中樞命名空間的連接字串:取得連接字串。Then, get the connection string for the Event Hubs namespace by following instructions from the article: Get connection string. 您稍後會在本快速入門中使用連接字串。You use the connection string later in this quickstart.

傳送事件Send events

本節說明如何建立可將事件傳送至事件中樞的 Java 應用程式。This section shows you how to create a Java application to send events an event hub.

加入 Azure 事件中樞程式庫的參考Add reference to Azure Event Hubs library

Maven 中央存放庫中具有適用於事件中樞的 Java 用戶端程式庫。The Java client library for Event Hubs is available in the Maven Central Repository. 您可以在 Maven 專案檔中用下列相依性宣告來參照此程式庫:You can reference this library using the following dependency declaration inside your Maven project file:

com.azure

azure-messaging-eventhubs

5.0.1

撰寫程式碼以將訊息傳送到事件中樞Write code to send messages to the event hub

針對下列範例,在您最喜愛的 Java 開發環境中,先為主控台/殼層應用程式建立新的 Maven 專案。For the following sample, first create a new Maven project for a console/shell application in your favorite Java development environment. 新增名為 Sender 的類別,並在此類別中新增下列程式碼:Add a class named Sender, and add the following code to the class:

import com.azure.messaging.eventhubs.*;

import static java.nio.charset.StandardChars

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值