대부분의 스트리밍 데이터 파이프라인에는 데이터 변환이 필요합니다. 일부 사용자는 데이터가 추출, 로드, 변환 (ELT) 파이프라인의 대상에 도달한 후에 데이터를 변환하는 것을 선호하는 반면, 다른 사용자는 추출, 로드, 변환 (ETL) 파이프라인에서 데이터를 처리하기 전에 데이터를 변환하는 것을 선호합니다. 기존에는 이 아키텍처에서 데이터 변환을 실행하려면 Dataflow 또는 Apache Flink와 같은 도구가 포함된 복잡한 파이프라인이 필요했습니다.
Pub/Sub는 스트리밍 파이프라인의 데이터 변환을 간소화하는 단일 메시지 변환 (SMT)을 제공합니다. SMT를 사용하면 Pub/Sub 내에서 직접 메시지 데이터와 속성을 간편하게 수정할 수 있습니다. SMT를 사용하면 추가 데이터 처리 단계나 별도의 데이터 변환 제품이 필요하지 않습니다.
SMT 사용 사례
고객이 웹사이트를 탐색할 때 맞춤형 제품을 추천하는 온라인 상점을 디자인해 보세요. 이를 위해 Pub/Sub를 사용하여 사이트에서의 고객 활동에 관한 실시간 데이터를 수집할 수 있습니다. 여기에는 조회된 제품, 장바구니에 추가된 제품, 제품에 부여된 평점에 관한 데이터가 포함됩니다.
하지만 이 원시 데이터를 맞춤 콘텐츠를 생성하는 데 사용하려면 몇 가지 조정이 필요한 경우가 많습니다. 예를 들어 원시 데이터에 사용 사례와 관련 없는 불필요한 세부정보가 포함되어 있을 수 있습니다. 이러한 세부정보의 예로는 고객의 브라우저 유형 또는 사이트 방문 시간이 있습니다. 데이터가 추천 시스템에 필요한 형식이 아닐 수도 있습니다. 예를 들어 타임스탬프가 다른 형식일 수 있거나 제품 ID를 다른 유형으로 변환해야 할 수 있습니다.
Pub/Sub SMT를 사용하여 다음과 같은 데이터 변환을 실행할 수 있습니다.
고객 개인 정보 보호를 위해 전체 이름, 주소와 같은 개인 식별 정보 (PII)를 삭제합니다.
제품 조회 및 구매와 같은 추천 관련 이벤트만 보관하고 고객 프로필 변경과 같은 기타 이벤트는 삭제합니다.
모든 타임스탬프, 통화 값, 제품 ID가 추천 시스템과 호환되는 일관된 형식과 유형을 준수하는지 확인합니다.
장바구니 총 금액 또는 제품 페이지 머물 시간과 같은 원시 데이터에서 새 데이터 필드를 생성합니다.
요약하자면 SMT는 다음을 비롯한 다양한 사용 사례를 지원합니다.
데이터 마스킹 및 수정: 신용카드 번호 또는 PII와 같은 필드를 마스킹하거나 수정하여 민감한 정보를 보호하고 데이터 개인 정보 보호 규정을 준수합니다.
데이터 형식 변환: 다운스트림 시스템과의 호환성을 보장하기 위해 여러 형식 간에 데이터를 변환합니다.
메시지 필터링: 콘텐츠 또는 속성을 기반으로 원치 않는 메시지를 필터링하여 관련성 높은 메시지만 처리합니다. SMT를 사용하면 Pub/Sub의 기본 제공 필터보다 더 복잡한 필터링 조건을 사용할 수 있습니다.
간단한 데이터 변환: 문자열 조작, 날짜 형식 지정, 수학 연산과 같은 기본 데이터 조작 작업을 실행합니다.
SMT의 샘플 메시지 흐름
이 이미지는 주제 및 구독 수준 모두에 SMT가 적용된 Pub/Sub 시스템의 예를 보여줍니다.
그림 1 SMT를 사용하여 메시지가 변환되는 방식
다음 절차는 Pub/Sub 시스템에서 메시지가 흐르는 방식을 보여줍니다.
게시자 애플리케이션 게시자 1과 게시자 2가 각각 Pub/Sub 주제에 메시지 A와 B를 게시합니다.
주제의 SMT는 메시지 A 및 B를 각각 메시지 A' 및 B'로 변환합니다.
스키마가 주제에 연결된 경우 변환된 메시지 A' 및 B'가 스키마에 대해 유효성 검사됩니다. 예를 들어 A'이 스키마와 일치하지 않으면 메시지 A의 게시가 오류와 함께 실패합니다.
변환된 메시지 A' 및 B'가 Pub/Sub 스토리지에 기록됩니다.
Pub/Sub는 이미지에 표시된 대로 구독 1 및 구독 2와 같은 모든 연결된 구독에 메시지 A' 및 B'를 전송합니다.
구독 1에 필터가 구성된 경우 메시지 A' 및 B'가 필터에 대해 평가됩니다. 필터와 일치하는 메일만 다음 단계로 진행됩니다. 다른 메시지는 Pub/Sub에서 자동으로 확인합니다.
구독 2에 필터가 구성된 경우 메시지 A' 및 B'가 필터에 대해 평가됩니다. 필터와 일치하는 메일만 다음 단계로 진행됩니다. 다른 메시지는 Pub/Sub에서 자동으로 확인합니다.
구독 1의 SMT는 메시지 A' 및 B'를 변환합니다. A'는 A''가 되고 B'는 B''가 됩니다.
구독 2의 SMT는 메시지 A' 및 B'를 변환합니다. A'는 A'로 유지되고 B'는 필터링됩니다.
구독 1이 페이로드 래핑 해제가 사용 설정된 푸시 구독인 경우 메시지 A'' 및 B''가 래핑 해제됩니다. 구독 2가 페이로드 래핑 해제가 사용 설정된 푸시 구독인 경우 A'가 래핑 해제됩니다.
구독자 1은 B'' 메시지를 수신하고, 구독자 2는 A'' 메시지를 수신하며, 구독자 3은 A' 메시지를 수신합니다.
구독자가 수신한 메시지를 확인합니다.
Pub/Sub는 확인된 메시지를 저장소에서 삭제합니다.
SMT에 관한 중요 정보
SMT는 Pub/Sub API에 통합되어 있으므로 주제 또는 구독 구성의 일부로 관리할 수 있습니다.
주제 또는 구독에서 최대 5개의 SMT를 사용 설정할 수 있습니다.
SMT는 단일 Pub/Sub 메시지에서 작동합니다. 여러 Pub/Sub 메시지를 집계할 수 없습니다.
SMT가 실행되면 데이터 및 속성을 포함한 Pub/Sub 메시지를 입력으로 사용합니다. 출력은 데이터 또는 속성이 수정된 변환된 Pub/Sub 메시지입니다.
순서 지정이 사용 설정된 구독에 정의된 SMT가 있고 메시지에서 SMT를 실행하면 오류가 발생하는 경우 동일한 순서 키의 후속 메시지가 구독자에게 전송되지 않습니다.
구독에 데드 레터 주제를 설정하여 메시지 백로그에서 오류를 발생시키는 메시지를 삭제하면 후속 메시지를 전송할 수 있습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[],[],null,["Most streaming data pipelines require data transformations. Some users prefer\ntransforming data after it reaches its destination in an extract, load,\ntransform (ELT) pipeline, while others opt for transforming data before its\ningestion in an extract, transform, and load (ETL) pipeline. Traditionally, this\narchitecture required complex pipelines with tools like Dataflow or\nApache Flink to perform data transformations.\n\nPub/Sub offers **Single Message Transforms** (SMTs) to simplify\ndata transformations for streaming pipelines. SMTs enable lightweight\nmodifications to message data and attributes directly within\nPub/Sub. SMTs eliminate the need for additional data processing\nsteps or separate data transformation products.\n\nSMTs use cases\n\nConsider designing an online store that wants to give customers personalized\nproduct recommendations as they browse the website. To do this, you can use\nPub/Sub to collect real-time data about customer activity on the\nsite. This includes data about the products viewed, the products added to the\ncart, and the ratings given to products.\n\nHowever, this raw data often needs some adjustments before it can be used to\ngenerate recommendations. For example, the raw data might contain extraneous\ndetails which are irrelevant for your use case. Examples of such details are the\ncustomer's browser type or the time they visited the site. The data might also\nnot be in the required format for the recommendation system. For example,\ntimestamps might be in different formats, or product IDs might need to be\nconverted to a different type.\n\nYou can use Pub/Sub SMTs to make data transformations\nsuch as the following:\n\n- Remove personally identifiable information (PII), such as full names and\n addresses, to protect customer privacy.\n\n- Retain only recommendation-relevant events, such as product views and\n purchases, and discard others, such as customer profile changes.\n\n- Ensure all timestamps, currency values, and product IDs adhere to a\n consistent format and type compatible with the recommendation system.\n\n- Generate new data fields from raw data, such as shopping cart total value or\n product page dwell time.\n\nIn summary, SMTs enable a wide range of use cases, including the following:\n\n- **Data masking and redaction**: Protect sensitive data by masking or\n redacting fields like credit card numbers or PII, aiding compliance with\n data privacy regulations.\n\n- **Data format conversion**: Transform data between different formats to\n ensure compatibility with downstream systems.\n\n- **Message filtering** : Process only relevant messages by filtering out\n unwanted messages based on content or attributes. SMTs allow for more\n complex filtering conditions than Pub/Sub's\n [built-in filters](/pubsub/docs/subscription-message-filter).\n\n- **Simple data transformations**: Perform basic data manipulation tasks, such\n as string manipulation, date formatting, or mathematical operations.\n\nSample message flow for SMTs\n\nThe image shows an example Pub/Sub system with SMTs applied at both the\ntopic and subscription levels.\n**Figure 1** How messages are transformed with SMTs.\n\n\u003cbr /\u003e\n\nThe following procedure shows how the messages flow in the Pub/Sub\nsystem:\n\n1. The publisher applications **Publisher 1** and **Publisher 2** publish\n messages **A** and **B** respectively to the Pub/Sub topic.\n\n2. The topic's SMTs transform messages **A** and **B** into messages **A'** and\n **B'**, respectively.\n\n3. If a schema is attached to the topic, the transformed messages **A'** and\n **B'** are validated against the schema. If, for example, **A'** does not\n match the schema, the publish of message **A** fails with an error.\n\n4. The transformed messages **A'** and **B'** are written to\n Pub/Sub storage.\n\n5. Pub/Sub delivers messages **A'** and **B'** to all attached\n subscriptions, which are **Subscription 1** and **Subscription 2** as shown\n in the image.\n\n6. If **Subscription 1** has a filter configured, messages\n **A'** and **B'** are evaluated against the filter. Only messages matching\n the filter proceed to the next step. Other messages are automatically\n acknowledged by Pub/Sub.\n\n7. If **Subscription 2** has a filter configured, messages\n **A'** and **B'** are evaluated against the filter. Only messages matching\n the filter proceed to the next step. Other messages are automatically\n acknowledged by Pub/Sub.\n\n8. **Subscription 1** 's SMTs transform messages **A'** and **B'** . **A'**\n becomes **A''** and **B'** becomes **B''**.\n\n9. **Subscription 2** 's SMTs transform messages **A'** and **B'** . **A'**\n remains as **A'** and **B'** is filtered out.\n\n10. If **Subscription 1** is a push subscription with payload unwrapping\n enabled, messages **A''** and **B''** are unwrapped. If\n **Subscription 2** is a push subscription with payload unwrapping\n enabled, **A'** is unwrapped.\n\n11. **Subscriber 1** receives message **B''** , **Subscriber 2** receives\n message **A''** , and **Subscriber 3** receives message **A'**.\n\n12. Subscribers acknowledge the received messages.\n\n13. Pub/Sub deletes the acknowledged messages from storage.\n\nImportant information about SMTs\n\n- SMTs are integrated into the Pub/Sub\n API, allowing you to manage them as part of your topic or subscription\n configurations.\n\n- Up to 5 SMTs can be enabled on a topic or subscription.\n\n- SMTs operate on a single Pub/Sub message. They\n cannot aggregate multiple Pub/Sub messages.\n\n- When a SMT is run, it takes as input the Pub/Sub message,\n including its data and attributes. The output is a transformed\n Pub/Sub message, with modifications to its data or attributes.\n\n- If you have an SMT defined on a subscription that has ordering enabled and\n executing the SMT on any message throws an error, the subsequent messages\n for the same ordering key are not delivered to the subscriber.\n [Set up a dead-letter topic on the subscription](/pubsub/docs/handling-failures)\n to remove such a message that throws an error from the backlog of messages\n so subsequent messages can be delivered.\n\nTypes of SMTs\n\n- [User Defined Functions](/pubsub/docs/smts/udfs-overview)\n\nWhat's next\n\n- [Choose between topic and subscription SMTs](/pubsub/docs/smts/choose-smts)\n\n- [Learn about User Defined Functions](/pubsub/docs/smts/udfs-overview)\n\n- [Create a topic with SMTs](/pubsub/docs/smts/create-topic-smt)\n\n- [Create a subscription with SMTs](/pubsub/docs/smts/create-subscription-smt)"]]