Share via


11단원: Weather 응용 프로그램에 이벤트 전송

이 단계에서는 Transact-SQL 스크립트를 사용하여 Weather 응용 프로그램에 이벤트를 전송한 다음 결과 알림을 확인합니다.

이벤트 데이터

이벤트는 알림 응용 프로그램에서 알림을 생성하는 데 사용하는 데이터입니다. 사용자가 작성하는 알림 생성 쿼리(예: 5단원의 쿼리)는 이벤트 데이터와 구독 데이터를 조인하여 알림을 생성합니다.

알림을 생성하는 쿼리는 처리할 데이터가 있는 각 생성자 퀀텀 중에 실행됩니다. 이벤트 규칙은 하나 이상의 이벤트 일괄 처리가 도착한 임의의 퀀텀에서 실행됩니다. 예약 규칙은 처리할 예약된 구독이 있는 임의의 퀀텀에서 실행됩니다.

이벤트 데이터가 없으면 규칙을 실행할 필요가 없습니다. 그러므로 알림이 생성되지 않습니다.

WeatherData 이벤트

이 응용 프로그램의 경우 이벤트 전송 저장 프로시저를 사용하여 이벤트 일괄 처리를 전송합니다. 먼저 NSEventBeginBatchWeatherData 저장 프로시저를 사용하여 이벤트 일괄 처리를 엽니다. WeatherSPEventProvider 호스팅되지 않은 이벤트 공급자를 6단원에서 정의한 이벤트 공급자로 지정합니다.

ms170427.Caution(ko-kr,SQL.90).gif주의:
이러한 문을 개별적으로 실행하지 마십시오. 개별적으로 실행하면 이벤트 일괄 처리를 매번 열고 닫기 때문에 동일한 트랜잭션으로 실행해야 합니다. 이러한 쿼리를 실행하려면 이 단원의 뒷부분에서 설명하는 대로 AddWeatherEvents.sql 스크립트를 실행합니다.
-- Use the weather application's database.
USE TutorialWeather;
-- Start an event batch.
DECLARE @BatchID bigint;
EXEC dbo.NSEventBeginBatchWeatherData N'WeatherSPEventProvider', @BatchID OUTPUT;

이벤트 일괄 처리를 만든 후 NSEventWriteWeatherData 저장 프로시저를 사용하여 3개의 weather 이벤트를 추가합니다. 이벤트 일괄 처리 ID를 지정한 다음 이벤트 필드 값을 지정합니다. 다음은 예제 이벤트입니다.

-- Submit events.
EXEC dbo.NSEventWriteWeatherData
    @EventBatchId=@BatchID,
    @City=N'Seattle',
    @Date=CONVERT(DATETIME, '2005-04-20 13:00:00', 120),
    @Low = 31,
    @High = 52,
    @Forecast=N'Sunny'

이 저장 프로시저를 사용하여 3개의 이벤트를 전송한 후 NSEventFlushBatchWeatherData를 사용하여 이벤트 일괄 처리를 닫고 응용 프로그램 데이터베이스에 전송합니다.

-- Flush event batch.
EXEC dbo.NSEventFlushBatchWeatherData @BatchID;

뷰와 저장 프로시저를 사용하여 이벤트 일괄 처리에 대한 정보를 볼 수 있도록 이벤트 일괄 처리 ID를 표시할 수 있습니다.

-- Display event batch ID
SELECT @BatchID 'Event Batch';

Weather 응용 프로그램에 이벤트 전송

AddWeatherEvents.sql 쿼리를 사용하여 Weather 응용 프로그램에 이벤트를 추가할 수 있습니다.

Weather 응용 프로그램에 이벤트를 전송하려면

  1. 솔루션 탐색기에서 Weather를 확장하고 쿼리를 확장한 다음 AddWeatherEvents.sql을 엽니다.

  2. Transact-SQL 코드를 검토합니다.

  3. F5 키를 눌러 쿼리를 실행합니다.

    두 개의 결과 집합을 받습니다. 첫 번째 결과 집합에서는 EventCount 값 3이 반환되고 두 번째 결과 집합에서는 event batch ID 1이 반환됩니다.

이벤트 데이터 보기

ViewWeatherEvents.sql 쿼리를 사용하여 방금 추가한 이벤트를 볼 수 있습니다.

이벤트 데이터를 보려면

  1. 솔루션 탐색기에서 ViewWeatherEvents.sql을 엽니다.

  2. Transact-SQL 코드를 검토합니다.

  3. F5 키를 눌러 쿼리를 실행합니다.

이벤트 일괄 처리를 여러 개 전송한 경우 EventBatchId 매개 변수를 적절히 변경합니다.

알림 보기

30초 정도 후 Notification Services에서 Notifications 폴더에 FileNotifications.htm 파일이 만들어집니다. 알림 데이터를 보려면 이 파일을 엽니다. 다음과 비슷한 3가지 알림을 받게 됩니다.

  • Notification Id: 1 Notification Class Name: WeatherNotifications Subscriber Id: stephanie Device Address: stephanie@adventure-works.com Protocol Fields: Body: Weather report for the city of Seattle [2/21/2005 2:01:00 PM]: Sunny
    Expected low temperature: 31 F.
    Expected high temperature: 52 F.
    For more information, visit our web site at http://www.msnbc.com/news/wea\_front.asp?ta=y\&tab=BW\&tp=\&czstr=Seattle.
    Thank you for using SQL Server Notification Services.
  • Notification Id: 2 Notification Class Name: WeatherNotifications Subscriber Id: david Device Address: david@adventure-works.com Protocol Fields: Body: Weather report for the city of Orlando [2/22/2005 2:01:00 AM]: Partly Cloudy
    Expected low temperature: 59 F.
    Expected high temperature: 81 F.
    For more information, visit our web site at http://www.msnbc.com/news/wea\_front.asp?ta=y\&tab=BW\&tp=\&czstr=Orlando.
    Thank you for using SQL Server Notification Services.
  • Notification Id: 3 Notification Class Name: WeatherNotifications Subscriber Id: richard Device Address: richard@adventure-works.com Protocol Fields: Body: Weather report for the city of Seattle [2/21/2005 2:01:00 PM]: Sunny
    Expected low temperature: 31 F.
    Expected high temperature: 52 F.
    For more information, visit our web site at http://www.msnbc.com/news/wea\_front.asp?ta=y\&tab=BW\&tp=\&czstr=Seattle.
    Thank you for using SQL Server Notification Services.

기본 제공 File 배달 프로토콜을 사용하기 때문에 이벤트에서 생성된 3가지 알림은 모두 하나의 파일에 포함됩니다. 이벤트를 더 전송하면 추가적인 알림이 이 파일에 추가됩니다.

각각의 알림에는 머리글이 있습니다. 머리글에는 구독자 ID, 장치 주소 등 알림에 대한 정보가 표시됩니다. 알림의 실제 내용은 "Body:" 다음부터 시작됩니다.

문제 해결

1분 내로 Notifications 폴더에 FileNotifications.htm 파일이 표시되지 않으면 Windows 이벤트 뷰어의 응용 프로그램 로그에서 Notification Services의 이벤트를 확인하십시오. Windows 서비스에는 Notifications 폴더에 쓸 수 있는 권한이 없을 수도 있습니다.

ViewNotifications.sql 쿼리를 실행하면 WeatherNotifications 알림 클래스에 대해 생성된 모든 알림에 대한 정보를 볼 수 있습니다.

알림 정보를 보려면

  1. 솔루션 탐색기에서 Weather를 확장하고 쿼리를 확장한 다음 ViewNotifications.sql을 두 번 클릭합니다.

  2. F5 키를 눌러 쿼리를 실행합니다.

    DeliveryStatusDescription 열에서 알림 배달에 대한 정보를 찾아봅니다. 오류가 발생하면 응용 프로그램 로그에 추가 정보가 제공됩니다.

  3. ViewSubscribersAndDevices.sql을 닫습니다.

다음 단계

이 자습서에서는 Notification Services 응용 프로그램에 대한 간단한 프로토타입을 구축하는 방법을 살펴보았습니다. Notification Services에 대한 학습을 계속하려면 다음 리소스를 사용하십시오.

참고 항목

개념

Notification Services 자습서

관련 자료

알림 솔루션 빌드
SQL Server Notification Services 소개

도움말 및 정보

SQL Server 2005 지원 받기