Altbilgi içeriğine atla
.NET YARDıM

NServiceBus C# (Geliştiriciler İçin Nasıl Çalışır)

NServiceBus, dağıtık sistem geliştirmeyi kolaylaştıran .NET Framework için güçlü ve uyarlanabilir bir hizmet otobüsüdür. Sunduğu güçlü mesajlaşma örüntüleri, birden çok mikro hizmet ve uygulamada güvenilir mesaj işleme ve teslimini garanti eder. NServiceBus, temel altındaki mesajlaşma mimarisini soyutlar; geliştiricilerin dağıtık sistemler kurmanın ayrıntıları yerine iş mantığına odaklanmasını sağlar.

Aksine, IronPDF, PDF dosyalarını oluşturmak, görüntülemek ve değiştirmek için popüler bir .NET kütüphanesidir. ASPX dosyaları ve HTML gibi çeşitli kaynaklardan PDF oluştururken kullanım kolaylığı ve etkinliğiyle bilinir.

NServiceBus ve IronPDF'yi birleştirerek, iş operasyonlarının bir parçası olarak PDF belgeleri oluşturabilen ve yönetebilen, güvenilir, ölçeklenebilir ve bakımı kolay yazılım sistemleri geliştirebilirsiniz.

Bu makalede, basit bir C# NServiceBus projesinin nasıl yapılandırılacağını ve IronPDF ile nasıl birleştirileceğini inceleyeceğiz; böylece dağıtık bir uygulama mimarisinde PDF belgelerini yönetme ve üretme için düzenli bir iş akışı oluşturabilirsiniz. Bu giriş dersini okuduktan sonra, bu iki etkili teknolojinin dağıtık bir ortamda PDF ile ilgili görevlerinizi nasıl basitleştirebileceğini açıkça anlayacaksınız.

NServiceBus C# nedir?

NServiceBus, dağıtık sistemler ve servis odaklı .NET mimarileri oluşturmayı kolaylaştıran güçlü ve uyarlanabilir bir çerçevedir. NServiceBus'u kullanarak çeşitli mesaj türlerini kolayca yönetebilir ve güvenilir iletişimi sağlayabilirsiniz. Bu, özellikle yönlendirme ve işleme sırasında sorunsuz çoklu uygulama ve benzeri mimarilerde önemlidir. NServiceBus'un mesaj işleyicileri, her mantıksal bileşenin sorunsuz bir şekilde etkileşime girmesini sağlayarak mesaj alma sorununu etkili bir şekilde çözer. NServiceBus'un aşağıda belirtilen önemli özellikleri vardır:

NServiceBus C# (Geliştiriciler İçin Nasıl Çalışır): Şekil 1 - NServiceBus C#

NServiceBus'un Özellikleri

Mesaj Tabanlı İletişim

NServiceBus, bir sistemdeki farklı hizmetler veya bileşenler arasında mesaj tabanlı iletişimi teşvik eder. Bileşenleri birbirinden ayırarak bu yöntem, yönetimi ve ölçeklenebilir tasarımlar oluşturmayı kolaylaştırır.

Güvenilir Mesajlaşma

Tekrar denemeleri, geçici kuyrukları ve diğer hata toleranslı teknikleri otomatik olarak yöneterek güvenilir mesaj teslimini garanti eder. Ağdaki kesintiler ve diğer arızların sık karşılaşıldığı dağıtık sistemlerde bu güvenilirlik son derece önemlidir.

Yayınlama/Abonelik Modeli

Yayınlama/Abonelik örüntüsü, hizmetlerin olaylar yayınlamasını ve başka hizmetlerin bu olaylara abone olmasını sağlayarak NServiceBus tarafından desteklenir. Bu, sistemin bir bileşeninde yapılan değişikliklerin diğer bileşenlerde yanıtlara neden olabildiği olay odaklı mimarilerin yaratılmasını sağlar.

Saga Yönetimi

NServiceBus, saga'lar için yerleşik desteği sayesinde uzun süreli iş süreçlerinin yönetilmesine olanak tanır. Saga'lar, hizmet platformunun durumu yürütmesine ve birden fazla hizmet arasında karmaşık işlemleri koordine etmesine olanak tanır.

Genişletilebilirlik ve Özelleştirme

Mesajların işlenmesi ve taşınması süreçlerini özelleştirmeyi sağlayan benzersiz bir genişletilebilirlik düzeyi sunar. Uyarlanabilirliği nedeniyle çeşitli senaryolarda kullanılabilir.

Çeşitli Mesajlaşma Platformlarıyla Entegrasyon

MSMQ, RabbitMQ, Azure Service Bus, Amazon SQS ve diğerleri dahil birçok mesajlaşma sistemi NServiceBus ile entegre edilebilir. Bu, geliştiricilere gereksinimlerini en iyi karşılayan iletişim altyapısı çözümünü seçme olanağı tanır.

C#'ta NServiceBus Oluşturma ve Yapılandırma

NServiceBus'u bir C# projesinde kullanmaya başlamadan önce geliştirme ortamınızı kurmalı, temel bir proje oluşturmalı ve temel bir mesajlaşma hizmeti ile senaryosu geliştirmelisiniz. İşte başlamanız için adım adım bir rehber.

Yeni Bir Visual Studio Projesi Oluşturun

Visual Studio'da konsol projesi oluşturma süreci basittir. Visual Studio ortamında aşağıdaki bu basit adımları kullanarak Konsol Uygulaması başlatın:

Kullanmadan önce bilgisayarınıza Visual Studio'nun yüklü olduğundan emin olun.

Yeni Bir Proje Başlat

Dosya'ya tıklayın, ardından Yeni'yi ve son olarak Proje'yi seçin.

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

Aşağıdaki proje şablonları referans listesinden 'Console App' veya 'Console App (.NET Core)' şablonunu seçebilirsiniz.

Projeniz için 'Ad' alanına bir ad tanımlayın.

NServiceBus C# (Geliştiriciler İçin Nasıl Çalışır): Şekil 3 - Proje için bir ad ve konum belirtin

Proje için bir depolama konumu seçin.

"Oluştur"a tıklamak Konsol uygulama projesini başlatacaktır.

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

NServiceBus Paketlerini Yükleyin

NuGet Paket Yöneticisi Konsolunu açmak için Araçlar > NuGet Paket Yöneticisi > Paket Yöneticisi Konsolu'na gidin.

NServiceBus NuGet paketini kurmak için aşağıdaki komutu çalıştırın.

Install-Package NServiceBus

Bir Taşıma Seçin

NServiceBus'in mesajları almak ve göndermek için taşımaya ihtiyacı vardır. Öğrenme Taşımasını kullanmak kolay olduğundan ve test ile geliştirme için uygun olduğundan bu transport'a bağlı kalacağız.

Öğrenme Taşıması için paketi çalıştırarak yükleyin.

Install-Package NServiceBus.RabbitMQ

NServiceBus'i Yapılandırin

Endpoint'i Ayarlayin

NServiceBus uç nokta yapılandırmasını Program.cs dosyanızda ayarlayın:

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# (Geliştiriciler İçin Nasıl Çalışır): Şekil 5 - Örnek konsol çıkışı

Bir Mesaj Oluşturun

Mesajı temsil etmek için yeni bir sınıf ekleyin.

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

Bir Mesaj İşleyici Oluşturun

Mesajı işlemek için yeni bir sınıf ekleyin.

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

Bir Mesaj Gönderme

Mesajı Endpoint'ten gönderin. İşlemeyi mesaj metoduyla iletmek için temel yolunuzu uyarlayın.

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# (Geliştiriciler İçin Nasıl Çalışır): Şekil 6 - Örnek konsol çıkışı

Uygulamayı başlatın ve projeyi oluşturun. Konsol 'Received message: Hello, NServiceBus!' mesajını görüntüleyebilir.

Başlarken

NServiceBus'i RabbitMQ ve IronPDF ile entegre etmek, mesajları NServiceBus ve RabbitMQ arasında yapılandırmayı ve IronPDF'yi kullanarak PDF oluşturmayı kapsar. İşte başlamak için kapsamlı bir nasıl yapılır kılavuzu:

IronPDF nedir?

IronPDF, PDF dosyaları oluşturmak, okumak, düzenlemek ve dönüştürmek için oluşturulmuş bir .NET kütüphanesidir. Bununla beraber, programcılar C# veya VB.NET uygulamalarında PDF dosyaları ile güçlü ve sezgisel bir araç kullanarak çalışabilirler. IronPDF'nin özellikleri ve yetenekleri aşağıda tam olarak açıklanmıştır:

NServiceBus C# (Geliştiriciler İçin Nasıl Çalışır): Şekil 7 - IronPDF: C# PDF Kütüphanesi ana sayfası

IronPDF'nin Özellikleri

[78] HTML'den PDF Oluşturma

[79] JavaScript, HTML ve CSS'yi PDF'ye dönüştürün. Modern web standartlarının iki önemli özelliği olan medya sorgularını ve duyarlı tasarımı destekler. HTML ve CSS kullanarak dinamik olarak stillendirilmiş PDF belgeleri, faturalar ve raporlar üretmek için kullanışlıdır.

[82] PDF Düzenleme

Halihazırdaki PDF'lere metin, resim ve diğer malzemeleri ekleyin. PDF dosyalarından metin ve resimler alabilirsiniz. Birden fazla PDF'yi tek bir dosyada birleştirin. PDF dosyalarını ayrı dokümanlar haline getirin. Anotasyonlar, dipnotlar, başlıklar ve yazılar ekleyin.

PDF Dönüştürme

Word, Excel, resim ve diğer dosya formatlarını PDF'e dönüştürün. PDF'den görüntüye dönüştürme (PNG, JPEG, vb.).

[86] Performans ve Güvenilirlik

Üretim ortamlarında yüksek performans ve güvenilirlik tasarım hedefidir. Büyük belgeleri en etkili şekilde işleyin.

IronPDF'nin Kurulumu

NuGet Paket Yöneticisi Konsolu'nu açarak IronPDF'yi yükleyin.

Install-Package IronPdf

Mesajlı Göndericiyi Yapılandırın

Messages, hem göndericinin hem de alıcının kullanacağı ortak bir proje (class library) 'dir. Messages projesinde mesaj sınıfı tanımlayın. Messages adında yeni bir Class Library projesi oluşturun ve çözünürlüğe ekleyin.

Mesajı Tanımla:

Messages projesi içinde, GeneratePdfMessage.cs adında yeni bir sınıf oluşturun:

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

Hem Gönderici hem de Alıcı projelerinde, Messages projesine bir referans dahil edin.

Gönderici projesinde NServiceBus endpoint yapısını mesaj teslimatı için RabbitMQ kullanacak şekilde ayarlayın.

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

Endpoint Yapılandırması: endpoint, EndpointConfiguration('SenderEndpoint') çağrılarak 'SenderEndpoint' adıyla başlatılır.

endpointConfiguration taşıma yapılandırmasıdır. Yerel bir RabbitMQ örneğine bağlanarak UseTransport() yöntemi, NServiceBus'ın taşıma mekanizması olarak RabbitMQ'yu kullanmasını ayarlar.

Başarısız mesajların gönderileceği ve işlenen mesajların denetleneceği kuyruklar, sırasıyla SendFailedMessagesTo("error") ve AuditProcessedMessagesTo("audit") kullanılarak yapılandırılır.

Mesaj Gönderildi: endpointInstance.Send("ReceiverEndpoint", message) bir GeneratePdfMessage mesajını 'ReceiverEndpoint'e gönderir.

PDF oluşturmak için Alıcıyı Yapılandırın

Alıcı projesinde, RabbitMQ üzerinden mesaj kabul etmek ve IronPDF kullanarak PDF üretmek için NServiceBus endpoint yapılandırmasını ayarlayın.

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

Bu yapılandırma, 'ReceiverEndpoint' alıcı endpointi için Gönderici yapılandırmasına benzer.

Mesaj İşleyici

Receiver projesinde, GeneratePdfMessageHandler.cs adında yeni bir sınıf oluşturun.

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

GeneratePdfMessageHandler mesajları GeneratePdfMessage türünde ele almak için IHandleMessages arayüzünü kullanır.

NServiceBus C# (Geliştiriciler İçin Nasıl Çalışır): Şekil 8 - Örnek konsol çıkışı

Handle Yöntemi: Mesaj alındıktan sonra, Handle fonksiyonu IronPDF kullanarak bir PDF oluşturur. Mesajdaki HTML içeriği, HtmlToPdf dönüştürücü kodu tarafından PDF'ye dönüştürülür ve ardından belirlenen çıktı yoluna kaydedilir.

NServiceBus C# (Geliştiriciler İçin Nasıl Çalışır): Şekil 9 - NServiceBus ve RabbitMQ ile IronPDF kullanarak PDF çıktısı

Sonuç

NServiceBus, RabbitMQ ve IronPDF, C# dilinde entegre edilerek, PDF'leri dinamik ve güvenilir bir şekilde üretmesi gereken dağıtık sistemler için ölçeklenebilir ve kararlı bir çözüm sağlar. Bu kombinasyon, NServiceBus'ın mesaj işleme yeteneklerinden, RabbitMQ'nun mesaj broker olarak güvenilirliği ve uyarlanabilirliğinden ve IronPDF'in güçlü PDF düzenleme araçlarından yararlanır. Hizmetler arasındaki ayrışmayı sağlayan sonuç mimarisi, bağımsız evrilme ve ölçeklendirme olanağı sağlar.

RabbitMQ ayrıca, ağ veya uygulama hataları durumunda bile mesaj teslimatını garanti eder. NServiceBus mesaj yönlendirmeyi ve işlemeyi daha basit hale getirir ve IronPDF HTML metinlerinin yüksek kaliteli PDF belgelerine dönüştürülmesini mümkün kılar. Bu entegrasyon, sistemin bakımını ve güvenilirliğini artırmanın yanı sıra, büyük ölçekli gelişmiş uygulamalar geliştirmek için esnek bir yapı sağlar.

Son olarak, .NET programlama araçlarınıza IronPDF ve Iron Software ekleyerek, barkodlarla etkin bir şekilde çalışabilir, PDF üretebilir, OCR gerçekleştirebilir ve Excel ile bağlantı kurabilirsiniz. IronPDF'nin Lisanslama Sayfası, $799'dan başlayarak ek web uygulamaları ve yetenekler sağlamak ve daha verimli geliştirme sunmak için özelliklerini; Iron Software'in Resmi Sitesi'nin esnek paketinin performans, uyumluluk ve kullanım kolaylığını sorunsuz bir şekilde harmanlar.

Projeye özel olarak uyarlanmış iyi tanımlanmış lisans seçenekleri varsa, geliştiriciler en uygun modeli güvenle seçebilir. Bu faydalar, geliştiricilerin çeşitli zorlukları etkili ve şeffaf bir şekilde ele almasına olanak tanır.

Sıkça Sorulan Sorular

NServiceBus'u, C#'te dağıtılmış sistem geliştirme için nasıl kullanabilirim?

NServiceBus, mesajlaşma mimarisini soyutlayarak C#'ta dağıtılmış sistem geliştirmeyi basitleştirir. Bu, geliştiricilerin iş mantığına odaklanmasını sağlarken mikroservisler arasında güvenilir mesaj işleme ve teslimatı sağlar.

PDF yönetim kütüphaneleri ile NServiceBus entegrasyonunun faydaları nelerdir?

NServiceBus'un IronPDF gibi PDF yönetim kütüphaneleriyle entegrasyonu, dağıtılmış uygulamalar içinde verimli PDF oluşturma ve yönetimini sağlar, bu da ölçeklenebilir ve sürdürülebilir yazılım sistemleri sağlar.

NServiceBus ve RabbitMQ ile bir C# projesi nasıl kurulur?

Visual Studio'da yeni bir konsol uygulaması oluşturun, NServiceBus ve RabbitMQ NuGet paketlerini yükleyin ve kodunuzda uç nokta ve mesaj taşımasını yapılandırın.

NServiceBus, mesaj tabanlı iletişimi nasıl geliştirir?

NServiceBus, yayınla/abone ol modeli ve destan yönetimi gibi güvenilir mesajlaşma modelleri sağlayarak mesajların doğru bir şekilde dağıtılmış sistemler arasında teslim edilmesini ve işlenmesini sağlar.

NServiceBus kullanarak dağıtılmış sistemlerde IronPDF'nin rolü nedir?

NServiceBus kullanarak dağıtılmış sistemlerde IronPDF, belgelendirme süreçlerini otomatikleştirecek şekilde mesaj tabanlı iş akışlarına entegre edilebilen sağlam PDF oluşturma ve yönetim yetenekleri sunar.

C#'te dağıtılmış sistemlerde güvenilir PDF oluşturma nasıl sağlanır?

C#'te dağıtılmış sistemlerde güvenilir PDF oluşturma, mesaj işleme için NServiceBus ve PDF oluşturma için IronPDF'in entegrasyonu ile sağlanabilir; RabbitMQ'nun mesajlaşma yeteneklerini kullanarak görevleri koordine edin ve tutarlılığı sağlayın.

NServiceBus'ta yayınla/abone ol modeli nasıl çalışır?

NServiceBus'ta yayınla/abone ol modeli, hizmetlerin yayınlayabileceği ve diğer hizmetlerin abone olabileceği olayları sağlar. Bu, tek bir bileşendeki değişikliklerin diğer bileşenlerde aksiyonları tetikleyebileceği olay tabanlı bir mimariyi mümkün kılar; bu, sistem tepkiselliğini ve ölçeklenebilirliğini artırır.

NServiceBus'ta destan yönetiminin önemi nedir?

NServiceBus'ta destan yönetimi, birden çok hizmet boyunca uzun süren iş süreçlerini koordine etmek için önemlidir, bu da karmaşık iş akışlarının dağıtılmış sistemler içinde doğru ve tutarlı bir şekilde yürütülmesini sağlar.

Jacob Mellor, Teknoloji Direktörü @ Team Iron
Chief Technology Officer

Jacob Mellor, Iron Software'in Teknoloji Müdürü ve C# PDF teknolojisinin öncüsü olan vizyoner bir mühendis. Iron Software’in temel kod tabanının ilk geliştiricisi olarak, şirketin ürün mimarisini kuruluşundan bu yana şekillendirdi ve CEO Cameron Rimington ile birlikte NASA, Tesla ve ...

Daha Fazlasını Oku

Iron Destek Ekibi

Haftanın 5 günü, 24 saat çevrimiçiyiz.
Sohbet
E-posta
Beni Ara