事件批处理

云眼About 7 min

事件批处理

本主题介绍云眼灰度发布(特性标帜)AB实验 Java SDK 如何使用事件处理器将展示次数和转化事件批处理到单个有效负载中,然后再将其发送到云眼灰度发布(特性标帜)AB实验。

Eyeofcloud Feature Experimentation Java SDKopen in new window 现在将决策和转换事件批处理到单个有效负载中,然后再将其发送到 Eyeofcloud。这是通过称为事件处理器的新 SDK 组件实现的。

事件批处理的优点是,根据定义、配置和使用事件处理器的方式,减少对 Eyeofcloud 的出站请求数。这意味着,跟踪的展示次数和转化事件数量相同,网络流量就会减少。

在 Java SDK 中,提供接口的实现和批处理事件。可以根据两个参数控制批处理:BatchEventProcessor``EventProcessor

  • 批大小:定义在发送到云眼灰度发布(特性标帜)AB实验之前一起批处理的事件数。
  • 刷新间隔:定义任何批处理事件应发送到云眼灰度发布(特性标帜)AB实验的时间量。

当批大小达到指定的限制或刷新间隔达到指定的时间限制时,将发送由批处理有效负载组成的事件。 下面将更详细地介绍选项。BatchEventProcessor

📘 注意

事件批处理适用于现成事件调度程序和自定义事件调度程序。

事件批处理过程不会从事件中删除任何个人身份信息 (PII)。仍必须确保不会向云眼发送任何不必要的 PII。

基本示例

如果要使用默认配置(使用默认和配置),可以使用以下方法轻松实例化 SDK。默认情况下,批大小为 10,刷新间隔为 30 秒。BatchEventProcessor``AsyncEventHandler``HttpProjectConfigManager``EyeofcloudFactory

Java

import com.eyeofcloud.ab.Eyeofcloud; import com.eyeofcloud.ab.EyeofcloudFactory; public class App { public static void main(String[] args) { String sdkKey = args[0]; Eyeofcloud eyeofcloud = EyeofcloudFactory.newDefaultInstance(sdkKey); } }

高级示例

还可以使用构建器选项进行自定义(以及),如下例所示: BatchEventProcessor``AsyncEventHandler``HttpProjectConfigManager

Java

import com.eyeofcloud.ab.Eyeofcloud; import com.eyeofcloud.ab.config.HttpProjectConfigManager; import com.eyeofcloud.ab.event.AsyncEventHandler; import com.eyeofcloud.ab.event.BatchEventProcessor; import java.util.concurrent.TimeUnit; public class App { public static void main(String[] args) { String sdkKey = args[0]; ProjectConfigManager projectConfigManager = HttpProjectConfigManager.builder() .withSdkKey(sdkKey) .build(); EventHandler eventHandler = AsyncEventHandler.builder() .withQueueCapacity(20000) .withNumWorkers(1) .build(); // Here we are using the builder options to set batch size // to 50 events and flush interval to a minute. BatchEventProcessor batchProcessor = BatchEventProcessor.builder() .withBatchSize(50) .withEventHandler(eventHandler) .withFlushInterval(TimeUnit.MINUTES.toMillis(1)) .build(); Eyeofcloud eyeofcloud = Eyeofcloud.builder() .withConfigManager(projectConfigManager) .withEventProcessor(batchProcessor) .build(); } }

BatchEventProcessor

BatchEventProcessor is an implementation of where events are batched. The class maintains a single consumer thread that pulls events off of the and buffers them for either a configured batch size or a maximum duration before the resulting is sent to the and .EventProcessor``BlockingCollection``LogEvent``EventDispatcher``NotificationCenter

The following properties can be used to customize the BatchEventProcessor configuration using the Builder class

Builder methods

Use the following methods to customize the .BatchEventProcessor

Property

Default value

Description

withEventHandler

null

Required field. Specifies event handler to use to dispatch event payload to Eyeofcloud 灰度发布(特性标帜).

By default, if you create an instance, it passes in to .AsyncEventHandler``BatchEventProcessor

withBatchSize

10

The maximum number of events to batch before dispatching. Once this number is reached, all queued events are flushed and sent to Eyeofcloud灰度发布(特性标帜).

withFlushInterval

30000 (30 Seconds)

Maximum time after which to batch and send event payload to Eyeofcloud Feature Experimentation. In milliseconds.

withEventQueue

1000

BlockingCollection that queues individual events to be batched and dispatched by the executor.

withNotificationCenter

null

Notification center instance to be used to trigger any notifications to notify when event batches are flushed.

withExecutor

Single Thread Executor

Executor service that takes care of triggering event batching and subsequent dispatching to Eyeofcloud灰度发布(特性标帜).

withTimeout

5000

Maximum time to wait for event processor’s close to be executed. In milliseconds.

Advanced configuration

You can set the following properties can be set to override the default configuration for .BatchEventProcessor

event.processor.batch.size

10

Maximum size of batch of events to send to Eyeofcloud灰度发布(特性标帜).

event.processor.batch.interval

30000

Maximum time after which to batch and send event payload to Eyeofcloud Feature Experimentation. In milliseconds.

event.processor.close.timeout

5000

Maximum time to wait for event processor’s close to be executed. In milliseconds.

For more information, see Initialize SDK.

Side effects

The table lists other Eyeofcloud灰度发布(特性标帜) functionality that may be triggered by using this class.

Functionality

Description

LogEvent

Whenever the event processor produces a batch of events, a LogEvent object will be created using the EventFactory.
It contains batch of conversion and decision events.
This object will be dispatched using the provided event dispatcher and also it will be sent to the notification subscribers

Notification Listeners

Flush invokes the LOGEVENT notification listener if this listener is subscribed to.

Registering LogEvent listener

To register a LogEvent notification listener

Java

// There are two ways to register logEvent listener // 1) Using NotificationCenter. eyeofcloud.notificationCenter.addNotificationHandler(LogEvent.class, logEventHandler -> {}); // 2) Using addLogEventNotificationHandler method of eyeofcloud. eyeofcloud.addLogEventNotificationHandler(logEventHandler -> { });

LogEvent

LogEvent object gets created using EventFactoryopen in new window. It represents the batch of decision and conversion events we send to the Eyeofcloud Feature Experimentation backend.

Object

Type

Description

requestMethod
Required (non null)

RequestMethod (Enum)

The HTTP verb to use when dispatching the log event. It can be Get or Post.

endpointUrl
Required (non null)

String

URL to dispatch log event to.

requestParams
Required (non null)

Map<String, String>

Parameters to be set in the log event.

eventBatchopen in new window
Required

EventBatch

It contains all the information regarding every event which is batched. including list of visitors which contains UserEvent.

Close Eyeofcloud Feature Experimentation on application exit

If you enable event batching, you must call the Close method () before exiting. This ensures that queued events are flushed as soon as possible to avoid data loss.eyeofcloud.close()

Warning

Because the Eyeofcloud Feature Experimentation client maintains a buffer of queued events, you must call on the Eyeofcloud 灰度发布(特性标帜) instance before shutting down your application or whenever dereferencing the instance.close()

Method

Description

close()

Stops all executor threads and flushes the event queue. This method will also stop any that is running for the data-file manager.scheduledExecutorService

Updated about 2 months ago


[

Configure event dispatcher

](/experimentation/v4.0.0-full-stack/docs/configure-event-dispatcher-java)[

Customize logger

](/experimentation/v4.0.0-full-stack/docs/customize-logger-java)

Did this page help you?

Yes

No

创建用户上下文

介绍创建用户上下文方法,该方法为云眼灰度发布(特性标帜)AB实验中的标帜决策和事件创建用户上下文。

此方法的目的是创建用户并设置用户上下文一次,因此不必在每次做出标帜决策或跟踪事件时都指定用户。可以定义多个用户上下文。系统将用户上下文作为运行时对象返回,否则不会持久化。

版本

1.0.0-beta 或更高版本

描述

此调用为标帜决策和事件创建用户上下文。可以在 Eyeofcloud 客户端实例上成功调用此方法,甚至在完全配置实例之前也是如此。

参数

下表列出了必需参数和可选参数:

参数

类型

描述

(必选)用户 ID

字符串

用户的 ID。

属性
可选

Map

自定义键值字符串对的映射,指定系统用户用于受众群体定位的用户的属性。有关更多详细信息,请参阅以下部分。

受众群体属性

为用户设置自定义受众群体属性,可以使用这些属性来定位受众群体。可以将字符串、数字、布尔值和 nil 作为自定义用户属性值传递。如果要根据他们使用的应用程序变体定位访问群体,还可以传入格式为语义变体的open in new window字符串,然后在 Eyeofcloud 应用中定义受众条件。version

🚧 重要

在访问群体评估期间,如果没有为给定的访问群体条件传递有效的属性值(例如,如果在受众群体条件需要布尔值时传递字符串,或者忘记传递值),则系统会跳过该条件。发生这种情况时,SDK 日志会包含警告。

返回

返回一个 EyeofcloudUserContext 对象。有关详细信息,请参阅云眼用户上下文

Dart

// option 1: create a user, then set attributes var user = await flutterSDK.createUserContext("user123"); var attributes = <String, dynamic>{}; attributes["is_logged_in"] = false; attributes["app_version"] = "1.3.2"; user!.setAttributes(attributes); // option 2: pass attributes when creating the user var attributes = <String, dynamic>{}; attributes["is_logged_in"] = false; attributes["app_version"] = "1.3.2"; var eyeofcloudUserContext = await eyeofcloudClient.createUserContext("user123", attributes);

参见

云眼用户上下文

源文件

包含 Flutter SDK for Android Eyeofcloudopen in new window 和 Swift 实现的语言/平台源文件.java为 EyeofcloudClient.swiftopen in new window

Last update:
Contributors: “zhangweixue”