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

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

NServiceBus, dağıtık sistem geliştirmesini kolaylaştıran, .NET Framework için tasarlanmış güçlü ve uyarlanabilir bir hizmet otobüsüdür. Çok sayıda mikro hizmet ve uygulama arasında güvenilir mesaj işleme ve teslimatı sağlayan güçlü mesajlaşma modelleri sunar. NServiceBus, geliştiricilerin dağıtık sistemler oluşturmanın karmaşıklıkları yerine iş mantığına odaklanmasını sağlayarak, temel mesajlaşma mimarisini soyutlar.

Buna karşılık, IronPDF, PDF dosyaları oluşturmak, görüntülemek ve değiştirmek için popüler bir .NET kütüphanesidir. Çeşitli kaynaklardan, örneğin ASPX dosyalarından ve HTML'den, PDF oluşturmanın kolay ve çok verimli olduğu iyi bilinmektedir.

Geliştiriciler, NServiceBus ve IronPDF'yi birleştirerek, PDF belgeleri oluşturma ve yönetme yeteneğine sahip güvenilir, ölçeklenebilir ve sürdürülebilir yazılım sistemleri oluşturabilirler.

Bu makalede, basit bir C# NServiceBus projesinin nasıl kurulacağını ve IronPDF ile nasıl entegre edileceğini inceleyerek, dağıtık bir uygulama mimarisinde PDF belgelerini yönetmek ve üretmek için optimize edilmiş bir iş akışı oluşturabileceksiniz. Bu tanıtım eğiticisini okuduktan sonra, bu iki etkili teknolojinin dağıtık bir ortamda PDF ile ilgili görevlerinizi nasıl basitleştirebileceğini tam olarak bilmelisiniz.

What is NServiceBus C#?

NServiceBus, dağıtık sistemler ve hizmet odaklı .NET mimarileri oluşturmayı kolaylaştıran güçlü ve esnek bir çerçevedir. NServiceBus'u kullanarak, çeşitli mesaj türlerini kolayca yönetebilir ve güvenilir iletişim sağlayabilirsiniz. Bu, özellikle sorunsuz mesaj yönlendirme ve işlemenin hayati önem taşıdığı bir web uygulaması ve benzeri mimarilerde çok önemlidir. NServiceBus'ın mesaj işleyicileri, mesaj alımıyla etkili bir şekilde ilgilenir ve her mantıksal bileşenin sorunsuz bir şekilde etkileşime girmesini sağlar. NServiceBus'ın önemli özellikleri şunlardır:

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

NServiceBus'ın Özellikleri

Mesaj Tabanlı İletişim

NServiceBus, bir sistem içindeki farklı hizmetler veya bileşenler arasında mesaj tabanlı iletişimi teşvik eder. Bileşenleri ayırarak, bu yöntem daha kolay ölçeklenebilir ve yönetilebilir tasarımlar oluşturur.

Güvenilir Mesajlaşma

Yeniden denemeleri, başarısız mesajlar için kuyruğu ve diğer hata tolerans tekniklerini otomatik olarak yöneten sistem, güvenilir mesaj teslimatını garanti eder. Ağ kesintileri ve başarısızlıkların sık karşılaşıldığı dağıtık sistemlerde bu güvenilirlik çok önemlidir.

Yayınlama/Abone Olma Modeli

NServiceBus, hizmetlerin olayları yayınlamasına ve diğer hizmetlerin bu olaylara abone olmasına olanak tanıyan yayınlama/abone olma modelini destekler. Bu, bir bileşenindeki olaylara yapılan değişikliklerin diğer bileşenlerde tepki uyandırabileceği olay güdümlü mimarileri mümkün kılar.

Saga Yönetimi

NServiceBus, iç içe geçmiş süreçlerin yönetilmesini sağlayan entegre saga desteği sayesinde uzun süreli iş süreçlerini yönetmeyi sağlar. Saga'lar, hizmet platformunun durumu yönetmesine ve birden fazla hizmet arasında karmaşık işlemleri koordine etmesine olanak tanır.

Genişletilebilirlik ve Özelleştirme

Geliştiricilerin mesajların işleme, taşıma sürecini kişiselleştirmesine olanak tanıyan olağanüstü bir genişletilebilirlik seviyesi sunar. Uyarlanabilirliği sayesinde, çeşitli senaryolarda kullanılabilir.

Çeşitli Mesajlaşma Platformları ile Entegrasyon

MSMQ, RabbitMQ, Azure Service Bus, Amazon SQS ve diğer pek çok mesajlaşma sistemi, NServiceBus ile entegre edilebilir. Bu, geliştiricilerin gereksinimlerine en uygun iletişim altyapısı çözümünü seçmelerini sağlar.

Create and configure NServiceBus in C

NServiceBus'ı bir C# projesinde kullanmaya başlamadan önce geliştirme ortamınızı kurmalı, temel bir proje oluşturmalı ve temel bir mesajlaşma hizmeti ve senaryo inşa etmelisiniz. İşte sizi harekete geçirecek adım adım bir kılavuz.

Yeni Bir Visual Studio Projesi Oluşturun

Visual Studio'da, bir konsol projesi oluşturma süreci basittir. Bir Konsol Uygulaması başlatmak için Visual Studio ortamında şu basit adımları kullanın:

Visual Studio'yu PC'nize yüklediğinizden emin olun.

Yeni Bir Proje Başlatın

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 şablonu referans listesinden "Console App" veya "Console App (.NET Core)" şablonunu seçebilirsiniz.

Proje için "Ad" alanında bir ad sağlayın.

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

Proje için bir depolama konumu seçin.

"Oluştur"a tıklamak, Konsol uygulama projesini başlatacak.

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

NServiceBus Paketlerini Yükleyin

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

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

Install-Package NServiceBus

Bir Taşıma Seçin

Mesajları almak ve göndermek için NServiceBus tarafından bir taşıma gereklidir. Test ve geliştirme için kullanımı kolay olduğu ve iyi çalıştığı için Öğrenme Taşıması'nı kullanmaya devam edeceğiz.

Öğrenme Taşıması için paketi yüklemek üzere çalıştırın.

Install-Package NServiceBus.RabbitMQ

NServiceBus'ı Yapılandırın

Uç Noktayı Kurun

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 için Nasıl Çalışır): Şekil 5 - Örnek konsol çıktısı

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

Mesaj Gönderme

Uç Noktadan bir Mesaj Gönderin. Handler'ın yardımıyla bir mesajı iletmek için birincil 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 için Nasıl Çalışır): Şekil 6 - Örnek konsol çıktısı

Uygulamayı başlatın ve projeyi oluşturun. Konsol "Mesaj alındı: Merhaba, NServiceBus!" mesajını göstermelidir.

Başlarken

Bir C# projesinde, NServiceBus'ı RabbitMQ ve IronPDF ile entegre etmek, NServiceBus ve RabbitMQ arasında mesajlar yapılandırmayı ve PDF oluşturmak için IronPDF kullanmayı içerir. İşte sizi harekete geçirecek ayrıntılı bir kılavuz:

IronPDF nedir?

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

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

IronPDF Özellikleri

HTML'den PDF Üretimi

JavaScript, HTML, ve CSS'i PDF'e dönüştür. Medya sorguları ve duyarlı tasarım gibi modern web standartlarını destekler. HTML ve CSS kullanarak dinamik olarak biçimlendirilmiş PDF belgeleri, faturalar ve raporlar üretmek için yararlıdır.

PDF Düzenleme

Zaten var olan PDF'lere metin, resim ve diğer materyaller ekleyin. PDF dosyalarından metin ve resimler çıkarın. Bir dosyada birden fazla PDF birleştirin. PDF dosyalarını birkaç belgeye bölün. Açıklamalar, altbilgiler, üstbilgiler ve filigranlar ekleyin.

PDF Dönüşümü

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

Performans ve Güvenilirlik

Üretim ortamlarında yüksek performans ve güvenilirlik tasarım hedefleridir. Büyük belgeleri verimli bir şekilde yönetir.

IronPDF'in Kurulumu

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

Install-Package IronPdf

Mesaj ile Gönderici Yapılandırın

Mesajlar, hem göndericinin hem de alıcının kullanacağı ortak bir proje (sınıf kütüphanesi) niteliğindedir. Mesajlar projesinde mesaj sınıfını tanımlayın. Messages adlı yeni bir Class Library projesi oluşturun ve çözümünüze ekleyin.

Mesajı Tanımlayın:

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, Mesajlar projesine bir referans ekleyin.

Gönderici projesinde, mesaj teslimi için RabbitMQ kullanacak şekilde NServiceBus uç noktasını yapılandırı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

Uç Nokta Yapılandırması: uç nokta, yeni EndpointConfiguration("SenderEndpoint") çağırarak "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'ı taşıma mekanizması olarak RabbitMQ'yu kullanacak şekilde yapılandırır.

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

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

PDF Üretmek için Alıcıyı Yapılandırın

Alıcı projesinde, RabbitMQ üzerinden mesajları kabul etmek ve IronPDF kullanarak PDF üretmek üzere NServiceBus uç noktası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

"ReceiverEndpoint" alıcı uç noktası için bu kurulum, 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, GeneratePdfMessage tipindeki mesajları işlemek için IHandleMessages arayüzünü kullanır.

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

Handle Metodu: Mesajı aldıktan sonra, Handle fonksiyonu IronPDF kullanarak bir PDF oluşturur. Mesaj içerisindeki HTML içerik HtmlToPdf render kodu tarafından PDF'ye dönüştürülür ve ardından belirlenen çıkış yoluna kaydedilir.

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

Sonuç

NServiceBus, RabbitMQ ve IronPDF, C#'da, PDF'leri dinamik ve güvenilir bir şekilde oluşturması gereken dağıtık sistemler için ölçeklenebilir ve kararlı bir çözüm sağlamak üzere entegre edilebilir. Bu kombinasyon, NServiceBus'ın mesaj işleme yeteneklerinden, bir iletişim aracı olarak RabbitMQ'nun güvenilirliği ve esnekliğinden ve IronPDF'nin sağlam PDF düzenleme araçlarından yararlanır. Sonuçta elde edilen mimari, hizmetler arasında bağımsız evrim ve ölçeklenebilirlik sağlarken, servisi ayırır.

RabbitMQ ayrıca ağ veya uygulama hataları durumunda mesaj iletimini sağlar. NServiceBus mesaj yönlendirme ve işlemesini basitleştirir ve IronPDF, HTML metnini yüksek kaliteli PDF belgelerine dönüştürmeyi mümkün kılar. Bu entegrasyon, sadece sistemin sürdürülebilirliğini ve güvenilirliğini artırmakla kalmaz, aynı zamanda büyük ölçekli, karmaşık uygulamalar geliştirmek için esnek bir çerçeve sunar.

Son olarak, IronPDF ve Iron Software'i .NET programlama araç takımınıza ekleyerek, efektif bir şekilde barkodlarla çalışabilir, PDF'ler üretebilir, OCR gerçekleştirebilir ve Excel ile bağlantı kurabilirsiniz. IronPDF'nin Lisanslama Sayfası, $999 ile başlayan, özelliklerini ve performans, uyumluluk ve kullanım kolaylığını Iron Software'ın Resmi Sitesi'nin esnek bir süitiyle kusursuz bir şekilde birleştirerek ek web uygulamaları ve yetenekler ile daha verimli bir geliştirme sağlar.

Projeye özgü gereksinimlere göre özelleştirilmiş lisans seçeneklerinin net bir şekilde tanımlandığı durumlarda, geliştiriciler optimal modeli güvenle seçebilirler. Bu avantajlar, geliştiricilerin çeşitli zorlukları etkili ve şeffaf bir şekilde ele almalarını sağlar.

Sıkça Sorulan Sorular

NServiceBus'ı C#'ta dağıtık sistem geliştirme için nasıl kullanabilirim?

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

NServiceBus'ı, PDF yönetim kütüphaneleri ile entegre etmenin faydaları nelerdir?

NServiceBus'ı IronPDF gibi PDF yönetim kütüphaneleri ile entegre etmek, dağıtık uygulamalar içerisinde verimli PDF üretimi ve yönetimi sağlar, ölçeklenebilir ve sürdürülebilir yazılım sistemleri oluşturmaya olanak tanır.

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

NServiceBus ve RabbitMQ ile bir C# projesi kurmak için Visual Studio'da yeni bir Konsol Uygulaması oluşturun, NServiceBus ve RabbitMQ NuGet paketlerini yükleyin ve kodunuzda uç nokta ve mesajlaşma taşımacılığını yapılandırın.

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

NServiceBus, mesaj tabanlı iletişimi yayınla/abone ol modeli ve destan yönetimi gibi güvenilir mesajlaşma desenleri sağlayarak geliştirir, böylece mesajlar dağıtık sistemler arasında doğru bir şekilde iletilir ve işlenir.

Dağıtık sistemlerde NServiceBus kullanılırken IronPDF'nin rolü nedir?

IronPDF, NServiceBus kullanılarak dağıtık sistemlerde güçlü PDF üretimi ve manipülasyon yetenekleri sunarak mesaj tabanlı iş akışlarına entegre edilebilir, belge yönetim süreçlerini otomatikleştiren çözümler sağlar.

C# kullanarak dağıtık sistemlerde güvenilir PDF yaratımı nasıl sağlanır?

C# kullanarak dağıtık sistemlerde güvenilir PDF üretimi, mesaj işleme için NServiceBus ve PDF üretimi için IronPDF'yi entegre ederek sağlanabilir, RabbitMQ'nun mesajlaşma yeteneklerinden faydalanarak görevleri koordine etmek ve tutarlılığı sağlamak için kullanılabilir.

Yayınla/Abone ol modeli NServiceBus'da nasıl çalışır?

NServiceBus'da, yayınla/abone ol modeli hizmetlerin olayları yayınlamasına ve diğer hizmetlerin bunlara abone olmasına olanak tanır. Bu, bir bileşendeki değişikliklerin diğerlerinde eylemleri tetikleyebileceği bir olay odaklı mimari sağlar, sistemin yanıt verme yeteneğini ve ölçeklenebilirliğini artırır.

NServiceBus'da destan yönetiminin önemi nedir?

NServiceBus'da destan yönetimi, uzun süreli işletme süreçlerini birden fazla hizmet arasında koordine etmek için önemlidir, karmaşık iş akışlarının doğru ve tutarlı bir şekilde yürütülmesini sağlar.

Jacob Mellor, Teknoloji Direktörü @ Team Iron
Teknoloji Direktörü

Jacob Mellor, Iron Software'de Baş Teknoloji Yöneticisidir ve C# PDF teknolojisinde öncü bir mühendisdir. Iron Software'ın ana kod tabanının ilk geliştiricisi olarak, CEO Cameron Rimington ile birlikte şirketin ürün mimarisini 50'den fazla kişilik bir şirkete dönüştürmüştür ...

Daha Fazla Oku

Iron Destek Ekibi

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