> ## Documentation Index
> Fetch the complete documentation index at: https://developer.box.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 履歴からストリームへの移行

export const MultiRelatedLinks = ({sections = []}) => {
  if (!sections || sections.length === 0) {
    return null;
  }
  return <div className="space-y-8">
      {sections.map((section, index) => <RelatedLinks key={index} title={section.title} items={section.items} />)}
    </div>;
};

export const RelatedLinks = ({title, items = []}) => {
  const getBadgeClass = badge => {
    if (!badge) return "badge-default";
    const badgeType = badge.toLowerCase().replace(/\s+/g, "-");
    return `badge-${badge === "ガイド" ? "guide" : badgeType}`;
  };
  if (!items || items.length === 0) {
    return null;
  }
  return <div className="my-8">
      {}
      <h3 className="text-sm font-bold uppercase tracking-wider mb-4">{title}</h3>

      {}
      <div className="flex flex-col gap-3">
        {items.map((item, index) => <a key={index} href={item.href} className="py-2 px-3 rounded related_link hover:bg-[#f2f2f2] dark:hover:bg-[#111827] flex items-center gap-3 group no-underline hover:no-underline border-b-0">
            {}
            <span className={`px-2 py-1 rounded-full text-xs font-semibold uppercase tracking-wide flex-shrink-0 ${getBadgeClass(item.badge)}`}>
              {item.badge}
            </span>

            {}
            <span className="text-base">{item.label}</span>
          </a>)}
      </div>
    </div>;
};

export const Link = ({href, children, className, ...props}) => {
  const localizedHref = localizeLink(href);
  return <a href={localizedHref} className={className} {...props}>
      {children}
    </a>;
};

Boxでは、`admin_logs`を使用してライブイベントを登録しているアプリケーションを`admin_logs_streaming`に移行することをお勧めします。`admin_logs_streaming`を使用すると、レイテンシが低下し、一貫性が高まるだけでなく、遅れて届くイベントが見逃されません。`admin_logs`と`admin_logs_streaming`の間のイベントの重複は、イベントIDを使用して排除することが可能です。

## Enterpriseの`stream_type`の比較

### `admin_logs_streaming`のメリット

* 遅れて届くイベントが、登録しているアプリケーションで見逃されなくなる
* レイテンシが80%低下する (通常の操作時)
* より一貫性のあるレイテンシが実現する (通常の操作時)
* 遅れたイベントの埋め戻しをサービスで管理する必要がなくなったため、障害からの復旧がよりスムーズになる

### `admin_logs`と`admin_logs_streaming`の相違点

* 2週間分のイベント履歴 (リテンション) が提供される
* `created_after`および`created_before`フィルタパラメータがサポートされない
* 重複を含む可能性がある (「少なくとも1回」は保証されている)
* イベントが時系列で返されなくなる (イベントはほぼ処理された順で返される)

### `admin_logs`と`admin_logs_streaming`の類似点

* 同じ<Link href="/reference/resources/events">`GET /events`</Link> APIエンドポイントを共有する
* 同じイベントペイロードを返す (イベントIDを使用して2つのストリームタイプでのイベントの重複排除が可能)
* `event_type`によるフィルタが可能
* `stream_position`を使用したイベントのページネーションが可能

## `admin_logs`から`admin_logs_streaming`への移行方法

### 1. 既存のリクエストは以下のようになります

```sh theme={null}
curl https://api.box.com/2.0/events?stream_type=admin_logs&stream_position=1632893855 \
    -H "authorization: Bearer <ACCESS_TOKEN>"
```

### 2. `admin_logs_streaming`を使用して重複する既存のリクエストを開始します

* 2週間前から開始し、埋め戻しする:

  ```sh theme={null}
  curl https://api.box.com/2.0/events?stream_type=admin_logs_streaming&stream_position=0 \
      -H "authorization: Bearer <ACCESS_TOKEN>"
  ```

または

* 今すぐ開始し、並行して実行する:

  ```sh theme={null}
  curl https://api.box.com/2.0/events?stream_type=admin_logs_streaming&stream_position=now \
      -H "authorization: Bearer <ACCESS_TOKEN>"
  ```

### 3. これまでの結果のページネーションを行い、`admin_logs`イベントとの重複を排除します

```sh theme={null}
curl https://api.box.com/2.0/events?stream_type=admin_logs_streaming&stream_position=1632893855 \
    -H "authorization: Bearer <ACCESS_TOKEN>"
```

### 4. 十分と思われるまで重複を継続します

### 5. 古い`admin_logs`リクエストを無効にします

<Frame center shadow border>
  <img src="https://mintcdn.com/box/_tECS-SYBYV9K-kZ/images/guides/events/enterprise-events/migrate_to_stream.png?fit=max&auto=format&n=_tECS-SYBYV9K-kZ&q=85&s=e85b9690bbce576ff7bfd8836bd55697" alt="ストリームの移行フロー" width="612" height="151" data-path="images/guides/events/enterprise-events/migrate_to_stream.png" />
</Frame>

<RelatedLinks
  title="関連するAPI"
  items={[
{ label: translate("List user and enterprise events"), href: "/reference/get-events", badge: "GET" },
{ label: translate("Get events long poll endpoint"), href: "/reference/options-events", badge: "OPTIONS" }
]}
/>

<RelatedLinks
  title="関連するガイド"
  items={[
{ label: translate("Get Enterprise Events"), href: "/guides/events/enterprise-events/for-enterprise", badge: "GUIDE" }
]}
/>
