Azure 함수를 사용하면 응용 프로그램 인프라에 대한 걱정 없이 작은 코드 부분( 기능이라고함)을 실행할 수 있습니다. Azure 함수를 사용하면 클라우드 인프라가 응용 프로그램을 규모에 맞게 실행하는 데 필요한 모든 최신 서버를 제공합니다.
함수는 특정 이벤트 유형에 의해 트리거됩니다 . 지원되는 트리거는 데이터의 변경 사항에 응답, 메시지(예: 이벤트 허브) 응답, 일정에 따라 실행 또는 HTTP 요청의 결과입니다.
Azure Functions는 인프라를 명시적으로 프로비저닝하거나 관리할 필요 없이 이벤트 트리거된 코드를 실행할 수 있도록 해주는 서버를 사용하지 않는 컴퓨팅 서비스입니다.
Azure 이벤트 허브는 서버를 사용하지 않는 아키텍처를 위해 Azure 함수와 통합됩니다.
Visual Studio 코드를 사용하면…
Visual Studio 코드를 열려면 운영 체제의 검색(OSX에서 스포트라이트 검색, 윈도우의 작업 표시줄에서 검색)에 시각적 코드를 입력합니다. 찾을 수 없는 경우 연습 0 - 전제 조건에 설명된 단계를 반복해야 합니다.
연습 0 - 사전 필수 요건에서 등록하는 데 사용한 Azure 계정으로 로그온하면 Visual Studio 코드를 통해모든 이벤트 허브 리소스를 찾고 바인딩할 수 있습니다.
Visual Studio 코드에서 Azure 아이콘을 클릭합니다. 해당 옵션이 없는 경우 필요한 확장 프로그램의 설치에 문제가 있을 수 있습니다.
다음으로 Azure에 로그인선택:
로그인하려면 브라우저로 리디렉션됩니다. 등록하는 데 사용한 Azure 계정을 선택해야 합니다.
브라우저에 다음 화면이 표시되면 Visual Code Studio로 로그인됩니다.
Visual Code Studio로 돌아가기(Azure 구독 이름(예: Azure 구독 1):
Azure 구독 1 위로 마우스를 가져가면 섹션 위에 메뉴가 표시되며 새 프로젝트 만들기…:
프로젝트를 저장할 로컬 폴더를 선택하고 선택을 클릭합니다.
이제 프로젝트 만들기 마법사를 입력합니다. 프로젝트 의 언어로 Javascript를 선택합니다.
프로젝트의 첫 번째 함수 템플릿으로 Azure 이벤트 허브 트리거를 선택합니다.
함수의 이름을 입력하고 ldap-aep-event-hub-trigger와 같은 형식을 사용하고 Enter 키를 누릅니다.
새 로컬 앱 설정 만들기를 선택합니다.
이벤트 허브 네임스페이스를 선택합니다. 연습 2에서 정의한 이벤트 허브가 표시됩니다. 이 예에서 이벤트 허브 네임스페이스는 mmewis-aep-enablement입니다.
이벤트 허브를 선택합니다. 연습 2에서 정의한 이벤트 허브가 표시됩니다. 내 경우 mmewis-aep-enablement-event-hub:
이벤트 허브 정책으로 RootManageSharedAccessKey를 선택합니다.
기본값을 사용하려면 입력합니다.
프로젝트 를 여는 방법에 대해 작업 공간에 추가를 선택합니다.
프로젝트를 만든 후 index.js 를 클릭하여 편집기에서 파일을 엽니다.
Adobe Experience Platform이 이벤트 허브로 보낸 페이로드에는 세그먼트 ID의 다음이 포함됩니다.
[{
"segmentMembership": {
"ups": {
"ca114007-4122-4ef6-a730-4d98e56dce45": {
"lastQualificationTime": "2020-08-31T10:59:43Z",
"status": "realized"
},
"be2df7e3-a6e3-4eb4-ab12-943a4be90837": {
"lastQualificationTime": "2020-08-31T10:59:56Z",
"status": "realized"
},
"39f0feef-a8f2-48c6-8ebe-3293bc49aaef": {
"lastQualificationTime": "2020-08-31T10:59:56Z",
"status": "realized"
}
}
},
"identityMap": {
"ecid": [{
"id": "08130494355355215032117568021714632048"
}]
}
}]
Adobe Event Hub 함수는 AEP 응답 페이로드의 각 세그먼트에 대한 세그먼트 이름을 추가합니다. 이를 위해 Azure 함수는 Adobe IO 런타임 함수를 호출하여 Adobe Experience Platform에서 세그먼트 정의를 가져옵니다. 이 런타임 함수는 세그먼트 이름이 모두 및 ldap로 시작하는 세그먼트 정의를 반환합니다. 접두사가 모두 있는 세그먼트는 Adobe Experience Platform 환경에서 사용하는 기본 세그먼트입니다(예: 모두 - 홈 페이지 방문자).
Visual Studio 코드에서 받는 응답에는 모두시작하는 몇 개의 세그먼트가 있을 것이며, ldap - Luma Sports 팬 세그먼트도 포함해야 합니다. 그렇지 않은 경우 세그먼트의 이름이 정확하지 않을 수 있습니다.
{
"segments": {
"39f0feef-a8f2-48c6-8ebe-3293bc49aaef": {
"description": "mmeewis - Citi Signal Sports Fan",
"name": "mmeewis - Citi Signal Sports Fan"
},
"a77d96aa-d166-43b1-baba-005d35261b8a": {
"description": "all - Interest in Nadia Elements Shell",
"name": "all - Interest in Nadia Elements Shell"
},
"ca114007-4122-4ef6-a730-4d98e56dce45": {
"description": "all - Homepage Visitors",
"name": "all - Homepage Visitors"
}
}
}
Visual Studio 코드의 index.js에 있는 코드를 아래 코드로 바꿉니다. Adobe Experience Platform 실시간 CDP가 세그먼트 자격 조건을 이벤트 허브 대상으로 보낼 때마다 이 코드가 실행됩니다. 이 예에서 코드는 수신된 페이로드를 표시 및 개선하는 데 사용됩니다. 하지만 세그먼트 자격 조건을 실시간으로 처리하는 모든 기능을 상상할 수 있습니다.
// Marc Meewis - Solution Consultant Adobe - 2020
// Adobe Experience Platform Enablement - Module 18
const request = require('request');
const sandbox = "--module18sandbox--";
const ldap = "--demoProfileLdap--";
const segmentDefAPIEndpoint = "--jwtSegment--";
// Main function
// -------------
// This azure function is fired for each segment activated to the Adobe Exeperience Platform Real-time CDP Azure
// Eventhub destination
// This function enriched the received segment payload with the name fo the segment.
// You can replace this function with any logic that is require to process and deliver
// Adobe Experience Platform segments in real-time to any application or platform that
// would need to act upon an AEP segment qualiification.
//
module.exports = async function (context, eventHubMessages) {
return new Promise (function (resolve, reject) {
// fetch aep segment definitions first
getAEPSegmentInfo().then(function(segments) {
eventHubMessages.forEach((message, index) => {
// process each eventhub message
var segmentKeys = Object.keys(message.segmentMembership.ups);
for (var segmentKey of segmentKeys) {
// lookup the segment-id in the segment definitions and add the
// the segment name to the eventhub payload
var segmentContent = "";
if (segments.hasOwnProperty(segmentKey)) {
segmentName = segments[segmentKey].name;
}
else {
segmentName = "Not Found";
}
// add the segment name to the payload
message.segmentMembership.ups[segmentKey].segmentName = segmentName;
}
});
// output the enriched Adobe Experience Platform payload send to Azure Eventhub
context.log('Message : ' + JSON.stringify(eventHubMessages, null, 2));
resolve();
});
});
};
// helper functions
function extractSegmentDenitions(segments, segmentdata) {
for (var s=0; s < segmentdata.length; s++) {
var segmentDef = segmentdata[s];
var segment = {};
segment.name = segmentDef.name;
segment.description = "";
if (segmentDef.hasOwnProperty("description")) {
segment.description = segmentDef.description;
}
segments[segmentDef.id] = segment;
}
return segments;
}
async function getAEPSegmentDefinitions(segmentFilter, segments) {
return new Promise (function (resolve, reject) {
const allSegmentsAPICall = segmentDefAPIEndpoint + "?segmentFilter=" + segmentFilter + "&sandboxId=" + sandbox;
var options = {
method:'get',
url:allSegmentsAPICall
};
request(options, function (error, response, body) {
if (error)
reject(error);
else {
segmentsResponse = JSON.parse(body)
segments = extractSegmentDenitions(segments, segmentsResponse.segmentData.segments);
resolve(segments);
}
});
});
}
async function getAEPSegmentInfo() {
var segments = {};
return new Promise (async function (resolve, reject) {
segments = await getAEPSegmentDefinitions("all", segments);
segments = await getAEPSegmentDefinitions(ldap, segments);
resolve(segments);
});
}
index.js에서 아래 코드를 붙여넣은 후 다음 예제에서 mmewis를 사용하여 ldap를 반영하도록 행 4 를 수정해야 합니다.
const ldap = "mmeewis";
결과는 다음과 같아야 합니다.
이제 프로젝트를 실행할 차례입니다. 이 단계에서는 프로젝트를 Azure에 배포하지 않습니다. 디버그 모드에서 로컬로 실행합니다. 실행 아이콘을 선택하고 녹색 화살표를 클릭합니다. 디버그 모드에서 프로젝트를 처음 실행할 때는 Azure 저장소 계정을 첨부하고 저장소 계정 선택을 클릭합니다.
저장소 계정 목록에서 Azure 저장소 계정 설정 18.1.4의 일부로 만든 계정을 선택합니다. 스토리지 계정의 이름은 ldapaepstorage(예: mmewisaepstorage.
이제 프로젝트가 실행되고 이벤트 허브의 이벤트에 대한 목록이 표시됩니다. 다음 연습에서는 시티 신호 웹 사이트에서 이러한 세그먼트에 대한 자격이 되는 동작을 보여줍니다. 따라서 이벤트 허브 트리거 함수의 터미널에서 세그먼트 자격 페이로드를 받게 됩니다.
프로젝트를 중지하려면 터미널 탭을 선택하고 터미널 창을 클릭한 다음 OSX의 CMD-C 또는 Windows의 경우 CTRL-C를누릅니다.
다음 단계: 18.6 엔드 투 엔드 시나리오