푸터 콘텐츠로 바로가기
.NET 도움말

NServiceBus C# (개발자를 위한 작동 방식)

NServiceBus는 분산 시스템 개발을 간소화하는 .NET Framework를 위해 설계된 강력하고 적응성이 있는 서비스 버스입니다. 제공하는 강력한 메시징 패턴은 여러 마이크로서비스와 애플리케이션 전반에 걸쳐 신뢰할 수 있는 메시지 처리 및 전송을 보장합니다. NServiceBus는 기본 메시징 아키텍처를 추상화하여 개발자가 분산 시스템 빌딩의 복잡성을 대신하여 비즈니스 로직에 집중할 수 있도록 합니다.

반면에 IronPDF는 PDF 파일을 생성, 보기 및 수정하기 위한 인기 있는 .NET 라이브러리입니다. 이는 ASPX 파일 및 HTML과 같은 다양한 소스에서 PDF를 생성하는 데 용이하고 매우 효율적인 것으로 잘 알려져 있습니다.

NServiceBus와 IronPDF를 결합하여 비즈니스 운영의 일환으로 PDF 문서를 생성하고 관리할 수 있는 안정적이고 확장 가능하며 유지 보수 가능한 소프트웨어 시스템을 구축할 수 있습니다.

이 글에서는 간단한 C# NServiceBus 프로젝트를 설정하고 IronPDF와 어떻게 통합할 수 있는지 살펴보아, 분산 애플리케이션 아키텍처 내 PDF 문서를 관리 및 생산하기 위한 효율적인 워크플로를 구축할 수 있게 합니다. 이 소개 튜토리얼을 읽고 나면 이 두 효과적인 기술이 분산 환경에서 PDF 관련 작업을 단순화하는 데 어떻게 협력할 수 있는지 정확히 알 수 있어야 합니다.

NServiceBus C#이란?

NServiceBus는 분산 시스템 및 서비스 지향 .NET 아키텍처를 쉬운 방식으로 만들 수 있도록 하는 강력하고 적응성이 있는 프레임워크입니다. NServiceBus를 활용하면 다양한 메시지 유형을 쉽게 관리하고 신뢰할 수 있는 통신을 보장할 수 있습니다. 이는 특히 매끄러운 메시지 라우팅과 처리가 필수적인 웹 애플리케이션 및 유사한 아키텍처에서 중요합니다. NServiceBus의 메시지 핸들러는 메시지를 수신하는 데 효과적으로 대처하여 각 논리적 구성 요소가 매끄럽게 상호 작용하도록 보장합니다. NServiceBus에는 다음과 같은 중요한 기능이 있습니다:

NServiceBus C# (개발자를 위한 작동 방식): 그림 1 - NServiceBus C#

NServiceBus의 기능

메시지 기반 통신

NServiceBus는 시스템 내 다양한 서비스 또는 구성 요소 간의 메시지 기반 통신을 장려합니다. 구성 요소를 분리함으로써 이 방법은 확장성과 관리가 쉬운 설계를 만들어냅니다.

신뢰할 수 있는 메시징

자동으로 재시도, 불량 편지 큐 및 기타 장애 내성 기술을 관리하여 신뢰할 수 있는 메시지 전달을 보장합니다. 분산 시스템에서 네트워크 장애 및 다른 문제로 인한 실패가 자주 발생하는 경우 이 신뢰성은 필수적입니다.

게시/구독 모델

NServiceBus는 게시/구독 패턴을 지원하여 서비스가 이벤트를 게시하고 다른 서비스가 이 이벤트를 구독할 수 있도록 합니다. 이것은 시스템의 한 구성 요소에서 이루어지는 이벤트의 수정이 다른 구성 요소에서 응답을 유발할 수 있는 이벤트 기반 아키텍처를 가능하게 합니다.

사가 관리

NServiceBus의 통합 사가 지원 덕분에 장기 실행 비즈니스 프로세스를 관리할 수 있습니다. 사가는 서비스 플랫폼이 여러 서비스 간의 상태를 관리하고 복잡한 작업을 조정할 수 있도록 합니다.

확장성과 사용자 정의

메시지의 처리, 전송 및 운송 과정을 개인화할 수 있도록 예외적인 수준의 확장성을 제공합니다. 적응력이 뛰어나 다양한 시나리오에서 사용할 수 있습니다.

다양한 메시징 플랫폼과의 통합

NServiceBus는 MSMQ, RabbitMQ, Azure Service Bus, Amazon SQS 등을 포함한 다양한 메시징 시스템과 통합될 수 있습니다. 이는 개발자가 자신들의 요구사항에 가장 적합한 통신 인프라 솔루션을 선택할 수 있도록 합니다.

C#에서 NServiceBus 생성 및 구성

C# 프로젝트에서 NServiceBus를 사용하기 시작하기 전에 개발 환경을 설정하고, 기본 프로젝트를 생성하며, 기본 메시징 서비스 및 시나리오를 구축해야 합니다. 여기 시작할 수 있도록 단계별 가이드가 있습니다.

새로운 Visual Studio 프로젝트 생성하기

Visual Studio에서 콘솔 프로젝트를 만드는 과정은 간단합니다. Visual Studio 환경에서 이 쉬운 단계들을 사용하여 콘솔 응용 프로그램을 시작하세요:

이용하기 전에 PC에 Visual Studio가 설치되어 있는지 확인하세요.

새 프로젝트 시작

파일을 클릭한 다음, 새로 만들기를 선택하고, 마지막으로 프로젝트를 선택하세요.

NServiceBus C# (How It Works For Developers): Figure 2 - Click New

아래 프로젝트 템플릿 참조 목록에서 'Console App' 또는 'Console App (.NET Core)' 템플릿을 선택할 수 있습니다.

프로젝트의 이름을 "이름" 필드에 입력하세요.

NServiceBus C# (개발자를 위한 작동 방식): 그림 3 - 프로젝트의 이름과 위치 제공

프로젝트의 저장소 위치를 선택하세요.

생성을 클릭하면 콘솔 응용 프로그램 프로젝트가 시작됩니다.

NServiceBus C# (How It Works For Developers): Figure 4 - Click create

NServiceBus Install-Package

NuGet 패키지 관리자 콘솔을 열려면 도구 > NuGet 패키지 관리자 > 패키지 관리자 콘솔로 이동하세요.

NServiceBus NuGet 패키지를 설치하려면 다음 명령어를 실행하세요.

Install-Package NServiceBus

전송 선택

NServiceBus는 메시지를 수신하고 전송하기 위해 전송 방식이 필요합니다. 사용하기 쉽고 테스트 및 개발에 적합하기 때문에 학습 전송을 계속 사용할 것입니다.

학습 전송 패키지를 설치하려면 다음을 실행하세요.

Install-Package NServiceBus.RabbitMQ

NServiceBus 구성

엔드포인트 설정

다음 파일에서 NServiceBus 엔드포인트 구성을 설정하십시오: Program.cs

using NServiceBus;
using System;
using System.Threading.Tasks;
using Messages;

class Program
{
    static async Task Main()
    {
        Console.Title = "Sender";
        var endpointConfiguration = new EndpointConfiguration("SenderEndpoint");

        // Use RabbitMQ Transport
        var transport = endpointConfiguration.UseTransport<RabbitMQTransport>();
        transport.ConnectionString("host=localhost");

        // Set up error queue
        endpointConfiguration.SendFailedMessagesTo("error");

        // Set up audit queue
        endpointConfiguration.AuditProcessedMessagesTo("audit");

        // Start the endpoint
        var endpointInstance = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false);
        Console.WriteLine("Press Enter to send a message...");
        Console.ReadLine();

        // Send a message
        var message = new MyMessage
        {
            Content = "Hello, NServiceBus with RabbitMQ!"
        };
        await endpointInstance.Send("ReceiverEndpoint", message).ConfigureAwait(false);
        Console.WriteLine("Message sent. Press Enter to exit...");
        Console.ReadLine();

        // Stop the endpoint
        await endpointInstance.Stop().ConfigureAwait(false);
    }
}
using NServiceBus;
using System;
using System.Threading.Tasks;
using Messages;

class Program
{
    static async Task Main()
    {
        Console.Title = "Sender";
        var endpointConfiguration = new EndpointConfiguration("SenderEndpoint");

        // Use RabbitMQ Transport
        var transport = endpointConfiguration.UseTransport<RabbitMQTransport>();
        transport.ConnectionString("host=localhost");

        // Set up error queue
        endpointConfiguration.SendFailedMessagesTo("error");

        // Set up audit queue
        endpointConfiguration.AuditProcessedMessagesTo("audit");

        // Start the endpoint
        var endpointInstance = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false);
        Console.WriteLine("Press Enter to send a message...");
        Console.ReadLine();

        // Send a message
        var message = new MyMessage
        {
            Content = "Hello, NServiceBus with RabbitMQ!"
        };
        await endpointInstance.Send("ReceiverEndpoint", message).ConfigureAwait(false);
        Console.WriteLine("Message sent. Press Enter to exit...");
        Console.ReadLine();

        // Stop the endpoint
        await endpointInstance.Stop().ConfigureAwait(false);
    }
}
Imports NServiceBus
Imports System
Imports System.Threading.Tasks
Imports Messages

Friend Class Program
	Shared Async Function Main() As Task
		Console.Title = "Sender"
		Dim endpointConfiguration As New EndpointConfiguration("SenderEndpoint")

		' Use RabbitMQ Transport
		Dim transport = endpointConfiguration.UseTransport(Of RabbitMQTransport)()
		transport.ConnectionString("host=localhost")

		' Set up error queue
		endpointConfiguration.SendFailedMessagesTo("error")

		' Set up audit queue
		endpointConfiguration.AuditProcessedMessagesTo("audit")

		' Start the endpoint
		Dim endpointInstance = Await Endpoint.Start(endpointConfiguration).ConfigureAwait(False)
		Console.WriteLine("Press Enter to send a message...")
		Console.ReadLine()

		' Send a message
		Dim message = New MyMessage With {.Content = "Hello, NServiceBus with RabbitMQ!"}
		Await endpointInstance.Send("ReceiverEndpoint", message).ConfigureAwait(False)
		Console.WriteLine("Message sent. Press Enter to exit...")
		Console.ReadLine()

		' Stop the endpoint
		Await endpointInstance.Stop().ConfigureAwait(False)
	End Function
End Class
$vbLabelText   $csharpLabel

NServiceBus C# (개발자를 위한 작동 방식): 그림 5 - 콘솔 출력 예시

메시지 생성

메시지를 나타내기 위해 새 클래스를 추가하세요.

public class MyMessage : IMessage
{
    public string Content { get; set; }
}
public class MyMessage : IMessage
{
    public string Content { get; set; }
}
Public Class MyMessage
    Implements IMessage

    Public Property Content As String
End Class
$vbLabelText   $csharpLabel

메시지 핸들러 생성

메시지를 처리하기 위해 새 클래스를 추가하세요.

using NServiceBus;
using System.Threading.Tasks;

public class MyMessageHandler : IHandleMessages<MyMessage>
{
    public Task Handle(MyMessage message, IMessageHandlerContext context)
    {
        Console.WriteLine($"Received message: {message.Content}");
        return Task.CompletedTask;
    }
}
using NServiceBus;
using System.Threading.Tasks;

public class MyMessageHandler : IHandleMessages<MyMessage>
{
    public Task Handle(MyMessage message, IMessageHandlerContext context)
    {
        Console.WriteLine($"Received message: {message.Content}");
        return Task.CompletedTask;
    }
}
Imports NServiceBus
Imports System.Threading.Tasks

Public Class MyMessageHandler
	Implements IHandleMessages(Of MyMessage)

	Public Function Handle(ByVal message As MyMessage, ByVal context As IMessageHandlerContext) As Task
		Console.WriteLine($"Received message: {message.Content}")
		Return Task.CompletedTask
	End Function
End Class
$vbLabelText   $csharpLabel

메시지 보내기

엔드포인트에서 메시지를 전송하세요. 핸들러의 도움으로 메시지를 전송하는 주요 방법을 조정하세요.

using NServiceBus;
using System;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        Console.Title = "Receiver";
        var endpointConfiguration = new EndpointConfiguration("ReceiverEndpoint");

        // Serialization configuration
        endpointConfiguration.UseSerialization<NewtonsoftJsonSerializer>();

        // Use RabbitMQ Transport
        var transport = endpointConfiguration.UseTransport<RabbitMQTransport>();
        transport.UseConventionalRoutingTopology(QueueType.Quorum);
        transport.ConnectionString("host=localhost");

        // Set up error queue
        endpointConfiguration.SendFailedMessagesTo("error");

        // Set up audit queue
        endpointConfiguration.AuditProcessedMessagesTo("audit");
        endpointConfiguration.EnableInstallers();

        // Start the endpoint
        var endpointInstance = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false);
        Console.WriteLine("Press Enter to exit...");
        Console.ReadLine();

        // Stop the endpoint
        await endpointInstance.Stop().ConfigureAwait(false);
    }
}
using NServiceBus;
using System;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        Console.Title = "Receiver";
        var endpointConfiguration = new EndpointConfiguration("ReceiverEndpoint");

        // Serialization configuration
        endpointConfiguration.UseSerialization<NewtonsoftJsonSerializer>();

        // Use RabbitMQ Transport
        var transport = endpointConfiguration.UseTransport<RabbitMQTransport>();
        transport.UseConventionalRoutingTopology(QueueType.Quorum);
        transport.ConnectionString("host=localhost");

        // Set up error queue
        endpointConfiguration.SendFailedMessagesTo("error");

        // Set up audit queue
        endpointConfiguration.AuditProcessedMessagesTo("audit");
        endpointConfiguration.EnableInstallers();

        // Start the endpoint
        var endpointInstance = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false);
        Console.WriteLine("Press Enter to exit...");
        Console.ReadLine();

        // Stop the endpoint
        await endpointInstance.Stop().ConfigureAwait(false);
    }
}
Imports NServiceBus
Imports System
Imports System.Threading.Tasks

Friend Class Program
	Shared Async Function Main() As Task
		Console.Title = "Receiver"
		Dim endpointConfiguration As New EndpointConfiguration("ReceiverEndpoint")

		' Serialization configuration
		endpointConfiguration.UseSerialization(Of NewtonsoftJsonSerializer)()

		' Use RabbitMQ Transport
		Dim transport = endpointConfiguration.UseTransport(Of RabbitMQTransport)()
		transport.UseConventionalRoutingTopology(QueueType.Quorum)
		transport.ConnectionString("host=localhost")

		' Set up error queue
		endpointConfiguration.SendFailedMessagesTo("error")

		' Set up audit queue
		endpointConfiguration.AuditProcessedMessagesTo("audit")
		endpointConfiguration.EnableInstallers()

		' Start the endpoint
		Dim endpointInstance = Await Endpoint.Start(endpointConfiguration).ConfigureAwait(False)
		Console.WriteLine("Press Enter to exit...")
		Console.ReadLine()

		' Stop the endpoint
		Await endpointInstance.Stop().ConfigureAwait(False)
	End Function
End Class
$vbLabelText   $csharpLabel

NServiceBus C# (개발자를 위한 작동 방식): 그림 6 - 콘솔 출력 예시

응용 프로그램을 시작하고 프로젝트를 빌드하세요. 콘솔에 'Received message: Hello, NServiceBus!'라는 메시지가 표시되어야 합니다.

시작하기

C# 프로젝트에서 NServiceBus를 RabbitMQ 및 IronPDF와 통합하는 것은 NServiceBus와 RabbitMQ 간의 메시지를 설정하고 IronPDF를 사용하여 PDF를 생성하는 것을 포함합니다. 여기 시작할 수 있는 철저한 방법 가이드가 있습니다:

IronPDF란 무엇입니까?

IronPDF는 PDF 파일을 생성, 읽기, 편집 및 변환하기 위해 설계된 .NET 라이브러리입니다. 이를 통해 프로그래머는 강력하고 직관적인 도구를 사용하여 C# 또는 VB.NET 애플리케이션에서 PDF 파일을 작업할 수 있습니다. IronPDF의 특성과 기능은 아래에 완전히 설명되어 있습니다:

NServiceBus C# (개발자를 위한 작동 방식): 그림 7 - IronPDF: C# PDF 라이브러리 홈페이지

IronPDF의 특징

HTML에서 PDF 생성

JavaScript, HTML, CSS 파일을 PDF로 변환합니다. 미디어 쿼리와 반응형 디자인을 지원하며, 이는 최신 웹 표준 두 가지입니다. HTML 및 CSS를 사용하여 동적으로 스타일링된 PDF 문서, 송장 및 보고서를 생성하는 데 유용합니다.

PDF 편집

이미 존재하는 PDF에 텍스트, 이미지 및 기타 자료 추가. PDF 파일에서 텍스트와 그림을 추출하세요. 여러 PDF를 하나의 파일로 결합. PDF 파일을 여러 문서로 분할. 주석, 바닥글, 머리글 및 워터마크 포함.

PDF 변환

Word, Excel, 이미지 및 기타 파일 형식을 PDF로 변환. PDF를 이미지(PNG, JPEG 등)로 변환합니다.

성능 및 신뢰성

생산 환경에서 고성능과 신뢰성을 설계 목표로 합니다. 대규모 문서를 효율적으로 관리합니다.

IronPDF 설치

NuGet 패키지 관리자 콘솔을 열어 IronPDF를 설치합니다.

Install-Package IronPdf

메시지로 발신자 구성

Messages는 발신자와 수신자 모두 사용할 클래스 라이브러리 형태의 공유 프로젝트입니다. Messages 프로젝트에서 메시지 클래스를 정의합니다. Messages라는 새 클래스 라이브러리 프로젝트를 생성하고 솔루션에 추가합니다.

메시지 정의:

메시지 프로젝트 내에서 GeneratePdfMessage.cs라는 새 클래스를 생성합니다.

using NServiceBus;

public class GeneratePdfMessage : IMessage
{
    public string Content { get; set; }
    public string OutputPath { get; set; }
}
using NServiceBus;

public class GeneratePdfMessage : IMessage
{
    public string Content { get; set; }
    public string OutputPath { get; set; }
}
Imports NServiceBus

Public Class GeneratePdfMessage
	Implements IMessage

	Public Property Content() As String
	Public Property OutputPath() As String
End Class
$vbLabelText   $csharpLabel

Sender 및 Receiver 프로젝트 모두에 Messages 프로젝트에 대한 참조를 포함합니다.

Sender 프로젝트에서 NServiceBus 엔드포인트를 RabbitMQ 메시지 전송에 사용하도록 설정합니다.

using NServiceBus;
using System;
using System.Threading.Tasks;
using Messages;

class Program
{
    static async Task Main()
    {
        Console.Title = "Sender";
        var endpointConfiguration = new EndpointConfiguration("SenderEndpoint");

        // Use RabbitMQ Transport
        var transport = endpointConfiguration.UseTransport<RabbitMQTransport>();
        transport.ConnectionString("host=localhost");

        // Set up error queue
        endpointConfiguration.SendFailedMessagesTo("error");

        // Set up audit queue
        endpointConfiguration.AuditProcessedMessagesTo("audit");
        endpointConfiguration.EnableInstallers();

        // Start the endpoint
        var endpointInstance = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false);
        Console.WriteLine("Press Enter to send a message...");
        Console.ReadLine();

        // Send a message
        var message = new GeneratePdfMessage
        {
            Content = "<h1>Hello, NServiceBus with RabbitMQ and IronPDF!</h1>",
            OutputPath = "output.pdf"
        };
        await endpointInstance.Send("ReceiverEndpoint", message).ConfigureAwait(false);
        Console.WriteLine("Message sent. Press Enter to exit...");
        Console.ReadLine();

        // Stop the endpoint
        await endpointInstance.Stop().ConfigureAwait(false);
    }
}
using NServiceBus;
using System;
using System.Threading.Tasks;
using Messages;

class Program
{
    static async Task Main()
    {
        Console.Title = "Sender";
        var endpointConfiguration = new EndpointConfiguration("SenderEndpoint");

        // Use RabbitMQ Transport
        var transport = endpointConfiguration.UseTransport<RabbitMQTransport>();
        transport.ConnectionString("host=localhost");

        // Set up error queue
        endpointConfiguration.SendFailedMessagesTo("error");

        // Set up audit queue
        endpointConfiguration.AuditProcessedMessagesTo("audit");
        endpointConfiguration.EnableInstallers();

        // Start the endpoint
        var endpointInstance = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false);
        Console.WriteLine("Press Enter to send a message...");
        Console.ReadLine();

        // Send a message
        var message = new GeneratePdfMessage
        {
            Content = "<h1>Hello, NServiceBus with RabbitMQ and IronPDF!</h1>",
            OutputPath = "output.pdf"
        };
        await endpointInstance.Send("ReceiverEndpoint", message).ConfigureAwait(false);
        Console.WriteLine("Message sent. Press Enter to exit...");
        Console.ReadLine();

        // Stop the endpoint
        await endpointInstance.Stop().ConfigureAwait(false);
    }
}
Imports NServiceBus
Imports System
Imports System.Threading.Tasks
Imports Messages

Friend Class Program
	Shared Async Function Main() As Task
		Console.Title = "Sender"
		Dim endpointConfiguration As New EndpointConfiguration("SenderEndpoint")

		' Use RabbitMQ Transport
		Dim transport = endpointConfiguration.UseTransport(Of RabbitMQTransport)()
		transport.ConnectionString("host=localhost")

		' Set up error queue
		endpointConfiguration.SendFailedMessagesTo("error")

		' Set up audit queue
		endpointConfiguration.AuditProcessedMessagesTo("audit")
		endpointConfiguration.EnableInstallers()

		' Start the endpoint
		Dim endpointInstance = Await Endpoint.Start(endpointConfiguration).ConfigureAwait(False)
		Console.WriteLine("Press Enter to send a message...")
		Console.ReadLine()

		' Send a message
		Dim message = New GeneratePdfMessage With {
			.Content = "<h1>Hello, NServiceBus with RabbitMQ and IronPDF!</h1>",
			.OutputPath = "output.pdf"
		}
		Await endpointInstance.Send("ReceiverEndpoint", message).ConfigureAwait(False)
		Console.WriteLine("Message sent. Press Enter to exit...")
		Console.ReadLine()

		' Stop the endpoint
		Await endpointInstance.Stop().ConfigureAwait(False)
	End Function
End Class
$vbLabelText   $csharpLabel

엔드포인트 구성: 엔드포인트는 new EndpointConfiguration("SenderEndpoint")를 호출하여 "SenderEndpoint"라는 이름으로 초기화됩니다.

endpointConfiguration은 전송 구성입니다. 로컬 RabbitMQ 인스턴스에 연결하여 UseTransport() 메서드를 통해 NServiceBus를 RabbitMQ를 전송 메커니즘으로 사용하도록 설정합니다.

오류 및 검사 대기열: 실패한 메시지를 보낼 위치와 처리된 메시지를 감사를 위해 보낼 위치는 각각 SendFailedMessagesTo("error")AuditProcessedMessagesTo("audit")를 사용하여 구성됩니다.

메시지 전송됨: endpointInstance.Send("ReceiverEndpoint", message)가 GeneratePdfMessage를 "ReceiverEndpoint"로 보냅니다.

PDF 생성 수신자 구성

Receiver 프로젝트에서 NServiceBus 엔드포인트를 RabbitMQ를 통해 메시지를 수락하고 IronPDF를 사용하여 PDF를 생성하도록 설정합니다.

using NServiceBus;
using System;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        Console.Title = "Receiver";
        var endpointConfiguration = new EndpointConfiguration("ReceiverEndpoint");

        // Use RabbitMQ Transport
        var transport = endpointConfiguration.UseTransport<RabbitMQTransport>();
        transport.ConnectionString("host=localhost");

        // Set up error queue
        endpointConfiguration.SendFailedMessagesTo("error");

        // Set up audit queue
        endpointConfiguration.AuditProcessedMessagesTo("audit");

        // Start the endpoint
        var endpointInstance = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false);
        Console.WriteLine("Press Enter to exit...");
        Console.ReadLine();

        // Stop the endpoint
        await endpointInstance.Stop().ConfigureAwait(false);
    }
}
using NServiceBus;
using System;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        Console.Title = "Receiver";
        var endpointConfiguration = new EndpointConfiguration("ReceiverEndpoint");

        // Use RabbitMQ Transport
        var transport = endpointConfiguration.UseTransport<RabbitMQTransport>();
        transport.ConnectionString("host=localhost");

        // Set up error queue
        endpointConfiguration.SendFailedMessagesTo("error");

        // Set up audit queue
        endpointConfiguration.AuditProcessedMessagesTo("audit");

        // Start the endpoint
        var endpointInstance = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false);
        Console.WriteLine("Press Enter to exit...");
        Console.ReadLine();

        // Stop the endpoint
        await endpointInstance.Stop().ConfigureAwait(false);
    }
}
Imports NServiceBus
Imports System
Imports System.Threading.Tasks

Friend Class Program
	Shared Async Function Main() As Task
		Console.Title = "Receiver"
		Dim endpointConfiguration As New EndpointConfiguration("ReceiverEndpoint")

		' Use RabbitMQ Transport
		Dim transport = endpointConfiguration.UseTransport(Of RabbitMQTransport)()
		transport.ConnectionString("host=localhost")

		' Set up error queue
		endpointConfiguration.SendFailedMessagesTo("error")

		' Set up audit queue
		endpointConfiguration.AuditProcessedMessagesTo("audit")

		' Start the endpoint
		Dim endpointInstance = Await Endpoint.Start(endpointConfiguration).ConfigureAwait(False)
		Console.WriteLine("Press Enter to exit...")
		Console.ReadLine()

		' Stop the endpoint
		Await endpointInstance.Stop().ConfigureAwait(False)
	End Function
End Class
$vbLabelText   $csharpLabel

이 설정은 "ReceiverEndpoint" 수신자 엔드포인트에 대해 Sender 구성과 유사합니다.

메시지 핸들러

Receiver 프로젝트에서 GeneratePdfMessageHandler.cs이라는 새 클래스를 생성합니다.

using NServiceBus;
using System;
using System.Threading.Tasks;
using Messages;
using IronPdf;

public class GeneratePdfMessageHandler : IHandleMessages<GeneratePdfMessage>
{
    public Task Handle(GeneratePdfMessage message, IMessageHandlerContext context)
    {
        Console.WriteLine($"Received message to generate PDF with content: {message.Content}");

        // Generate PDF
        var renderer = new HtmlToPdf();
        var pdf = renderer.RenderHtmlAsPdf(message.Content);
        pdf.SaveAs(message.OutputPath);
        Console.WriteLine($"PDF generated and saved to: {message.OutputPath}");

        return Task.CompletedTask;
    }
}
using NServiceBus;
using System;
using System.Threading.Tasks;
using Messages;
using IronPdf;

public class GeneratePdfMessageHandler : IHandleMessages<GeneratePdfMessage>
{
    public Task Handle(GeneratePdfMessage message, IMessageHandlerContext context)
    {
        Console.WriteLine($"Received message to generate PDF with content: {message.Content}");

        // Generate PDF
        var renderer = new HtmlToPdf();
        var pdf = renderer.RenderHtmlAsPdf(message.Content);
        pdf.SaveAs(message.OutputPath);
        Console.WriteLine($"PDF generated and saved to: {message.OutputPath}");

        return Task.CompletedTask;
    }
}
Imports NServiceBus
Imports System
Imports System.Threading.Tasks
Imports Messages
Imports IronPdf

Public Class GeneratePdfMessageHandler
	Implements IHandleMessages(Of GeneratePdfMessage)

	Public Function Handle(ByVal message As GeneratePdfMessage, ByVal context As IMessageHandlerContext) As Task
		Console.WriteLine($"Received message to generate PDF with content: {message.Content}")

		' Generate PDF
		Dim renderer = New HtmlToPdf()
		Dim pdf = renderer.RenderHtmlAsPdf(message.Content)
		pdf.SaveAs(message.OutputPath)
		Console.WriteLine($"PDF generated and saved to: {message.OutputPath}")

		Return Task.CompletedTask
	End Function
End Class
$vbLabelText   $csharpLabel

GeneratePdfMessageHandlerIHandleMessages 인터페이스를 사용하여 GeneratePdfMessage 유형의 메시지를 처리합니다.

NServiceBus C# (개발자를 위한 작동 방식): 그림 8 - 콘솔 출력 예시

핸들 메서드: 메시지를 수신한 후 Handle 함수가 IronPDF를 사용하여 PDF를 생성합니다. 메시지의 HTML 콘텐츠는 HtmlToPdf 렌더러 코드에 의해 PDF로 변환되고 지정된 출력 경로에 저장됩니다.

NServiceBus C# (개발자를 위한 작동 방식): 그림 9 - RabbitMQ와 함께 사용된 NServiceBus에서의 PDF 출력

결론

NServiceBus는 RabbitMQ 및 IronPDF와 통합되어 PDF를 동적이고 안정적으로 생성할 필요가 있는 분산 시스템을 위한 확장 가능하고 안정적인 솔루션을 제공합니다. 이 조합은 NServiceBus의 메시지 처리 기능, RabbitMQ의 신뢰성과 적응성, 그리고 IronPDF의 강력한 PDF 편집 도구를 활용합니다. 서비스 간의 디커플링이 보장되므로 자율적인 진화와 확장이 가능합니다.

RabbitMQ는 네트워크 또는 애플리케이션 오류가 발생해도 메시지 전송을 보장합니다. NServiceBus는 메시지 라우팅과 처리를 간소화하고, IronPDF는 HTML 텍스트를 고품질 PDF 문서로 변환할 수 있게 합니다. 이 통합은 대규모 애플리케이션 개발에 유연한 프레임워크를 제공하는 동시에 시스템의 유지 보수성과 신뢰성을 향상합니다.

마지막으로 .NET 프로그래밍 도구킷에 IronPDF와 Iron Software를 추가하면 바코드를 효율적으로 작업하고, PDF를 생성하고, OCR을 수행하며, Excel과 연결할 수 있습니다. IronPDF의 라이선싱 페이지는 $799에서 시작되며, Iron Software의 공식 사이트의 유연한 기능과 성능, 호환성, 사용 용이성을 결합하여 추가 웹 애플리케이션 및 기능과 더 효율적인 개발을 제공합니다.

프로젝트의 구체적인 요구 사항에 맞게 사용자 정의된 잘 정의된 라이선스 옵션이 있는 경우, 개발자는 자신 있게 최적의 모델을 선택할 수 있습니다. 이러한 장점은 개발자가 다양한 문제를 효과적이고 투명하게 처리할 수 있게 해 줍니다.

자주 묻는 질문

C#에서 분산 시스템 개발을 위해 NServiceBus를 어떻게 사용할 수 있나요?

NServiceBus는 메시징 아키텍처를 추상화하여 C#에서의 분산 시스템 개발을 단순화합니다. 이를 통해 개발자는 비즈니스 로직에 집중할 수 있으며, 마이크로서비스 간의 메시지 처리 및 전달의 신뢰성을 보장합니다.

PDF 관리 라이브러리와의 NServiceBus 통합의 이점은 무엇인가요?

IronPDF와 같은 PDF 관리 라이브러리와 NServiceBus를 통합하면 분산 애플리케이션 내에서 효율적인 PDF 생성 및 관리를 가능하게 하여 확장 가능하고 유지 관리 가능한 소프트웨어 시스템을 구축할 수 있습니다.

NServiceBus와 RabbitMQ로 C# 프로젝트를 설정하는 방법은 무엇인가요?

NServiceBus와 RabbitMQ로 C# 프로젝트를 설정하려면 Visual Studio에서 새로운 콘솔 응용 프로그램을 생성하고, NServiceBus 및 RabbitMQ NuGet 패키지를 설치한 후, 코드에서 엔드포인트와 메시징 전송을 구성하세요.

NServiceBus가 메시지 기반 통신을 어떻게 강화하나요?

NServiceBus는 발행/구독 모델과 사가 관리를 포함한 신뢰할 수 있는 메시징 패턴을 제공하여 분산 시스템 전역에 메시지가 올바르게 전달되고 처리되도록 보장하여 메시지 기반 통신을 강화합니다.

IronPDF는 NServiceBus를 사용하는 분산 시스템에서 어떤 역할을 하나요?

IronPDF는 문서 처리 과정을 자동화하기 위해 메시지 구동 워크플로에 통합될 수 있는 강력한 PDF 생성 및 조작 기능을 제공함으로써 NServiceBus를 사용하는 분산 시스템에서 중요한 역할을 합니다.

C#을 사용하여 분산 시스템에서 신뢰할 수 있는 PDF 생성을 어떻게 보장할 수 있나요?

C#을 사용한 분산 시스템에서의 신뢰할 수 있는 PDF 생성은 메시지 처리에 NServiceBus를 통합하고 PDF 생성을 위해 IronPDF를 사용하는 것으로, RabbitMQ의 메시징 기능을 활용하여 작업을 조정하고 일관성을 보장할 수 있습니다.

NServiceBus에서 발행/구독 모델이 어떻게 작동하나요?

NServiceBus에서 퍼블리시/구독 모델은 서비스들이 이벤트를 퍼블리시하여 다른 서비스들이 구독할 수 있도록 합니다. 이는 이벤트 주도 아키텍처를 가능하게 하여 한 구성 요소의 변화가 다른 구성 요소들에서 동작을 트리거하여 시스템의 반응성과 확장성을 향상시킵니다.

NServiceBus에서 사가 관리가 가지는 중요성은 무엇입니까?

NServiceBus에서 사가 관리는 여러 서비스에 걸친 장기 실행 비즈니스 프로세스를 조율하는 데 중요하며, 복잡한 워크플로우가 분산 시스템 내에서 올바르고 일관되게 실행되도록 보장합니다.

제이콥 멜러, 팀 아이언 최고기술책임자
최고기술책임자

제이콥 멜러는 Iron Software의 최고 기술 책임자(CTO)이자 C# PDF 기술을 개척한 선구적인 엔지니어입니다. Iron Software의 핵심 코드베이스를 최초로 개발한 그는 창립 초기부터 회사의 제품 아키텍처를 설계해 왔으며, CEO인 캐머런 리밍턴과 함께 회사를 NASA, 테슬라, 그리고 전 세계 정부 기관에 서비스를 제공하는 50명 이상의 직원을 보유한 기업으로 성장시켰습니다.

제이콥은 맨체스터 대학교에서 토목공학 학사 학위(BEng)를 최우등으로 취득했습니다(1998~2001). 1999년 런던에서 첫 소프트웨어 회사를 설립하고 2005년 첫 .NET 컴포넌트를 개발한 후, 마이크로소프트 생태계 전반에 걸쳐 복잡한 문제를 해결하는 데 전문성을 발휘해 왔습니다.

그의 대표 제품인 IronPDF 및 Iron Suite .NET 라이브러리는 전 세계적으로 3천만 건 이상의 NuGet 설치 수를 기록했으며, 그의 핵심 코드는 전 세계 개발자들이 사용하는 다양한 도구에 지속적으로 활용되고 있습니다. 25년의 실무 경험과 41년의 코딩 전문성을 바탕으로, 제이콥은 차세대 기술 리더들을 양성하는 동시에 기업 수준의 C#, Java, Python PDF 기술 혁신을 주도하는 데 주력하고 있습니다.

아이언 서포트 팀

저희는 주 5일, 24시간 온라인으로 운영합니다.
채팅
이메일
전화해