Fluent Brighter: Cómo Configurar PostgreSQL

Configura PostgreSQL con Fluent Brighter en .NET para outbox, inbox y gateway de mensajería: transacciones seguras, idempotencia y resiliencia en producción.

7 sept 2025 • 3 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

En artículos anteriores expliqué cómo integrar RabbitMQ con Fluent Brighter; en esta ocasión te muestro paso a paso cómo configurar PostgreSQL para habilitar outbox, inbox y el gateway de mensajería con Fluent Brighter en .NET, de forma segura, consistente y preparada para producción.

Requisitos: .NET 8 o netstandard2.0. Paquetes NuGet necesarios: Fluent.Brighter.Postgres para la integración con PostgreSQL y Paramore.Brighter.ServiceActivator.Extensions.Hosting para alojar el Service Activator y ejecutar procesos en segundo plano.

Fundamentos de Brighter en breve. Requests: los comandos se dirigen a un único destinatario y los eventos notifican a múltiples consumidores. Message Mapper: opcional si usas JSON por defecto, permite mapear entre mensajes Brighter y objetos de dominio. Request Handler: es la clase que procesa el mensaje y contiene tu lógica de negocio, donde podrás registrar logs, aplicar validaciones o publicar eventos derivados.

Configurar PostgreSQL con Fluent.Brighter. Comienza registrando AddFluentBrighter en tu contenedor DI; a partir de ahí defines suscripciones, publicaciones y los stores de inbox y outbox en PostgreSQL.

Suscripciones en PostgreSQL. Define AddPostgresSubscription para cada evento o comando que vayas a consumir. Asigna la cola o tópico, el tipo de message pump y la conexión a la base de datos. Si además integras otros transportes, crea el channel factory correspondiente y combina ambos enfoques sin perder la persistencia de inbox.

Publicaciones en PostgreSQL. Con AddPostgresPublication describes cómo se publican los mensajes salientes y en qué cola o tópico se encolarán. Esta capa trabaja con el outbox para garantizar entrega al menos una vez y reintentos controlados.

Outbox con PostgreSQL. Activa UsePostgresOutbox para persistir los mensajes salientes dentro de la misma transacción de tu caso de uso. Añade UseDbTransactionOutboxArchive para coordinar la transacción con tu base de datos de negocio y UseOutboxSweeper para barrer y reenviar mensajes pendientes o atascados. El ServiceActivatorHostedService es el proceso que extrae y publica desde el outbox.

Inbox con PostgreSQL. Habilita UsePostgresInbox para registrar los mensajes entrantes procesados y conseguir idempotencia; si tu handler es reejecutado, el inbox evita duplicados con claves de deduplicación basadas en el id del mensaje.

Configuración unificada. Con UsingPostgres defines una sola vez la cadena de conexión, nombre de tablas como el outbox, y habilitas UseInbox, UseOutbox, UsePublications y UseSubscriptions. En publicaciones puedes añadir varios eventos, por ejemplo GreetingEvent y FarewellEvent con sus respectivas colas, y en suscripciones asignar MessagePumpType Reactor para maximizar throughput y latencia baja.

Buenas prácticas. Usa transacciones por solicitud para consolidar cambios de dominio y escritura en outbox. Asegura claves y políticas de retención en las tablas de inbox y outbox. Ajusta intervalos del sweeper y políticas de reintento según el volumen. Controla la serialización y el mapeo si necesitas compatibilidad hacia atrás. Monitoriza métricas de procesamiento y latencias. Automatiza migraciones de esquema y activa el pooling de conexiones en el proveedor de PostgreSQL para optimizar recursos.

En Q2BSTUDIO llevamos estas arquitecturas a producción combinando patrones de mensajería, diseño orientado a dominio y pipelines resilientes. Si necesitas integrar mensajería confiable con Fluent Brighter y PostgreSQL dentro de un ecosistema de aplicaciones a medida, nuestro equipo puede ayudarte con arquitectura, desarrollo, despliegue y observabilidad de extremo a extremo. Descubre cómo aceleramos proyectos de desarrollo de software a medida con calidad empresarial, IA para empresas y automatización.

Nuestros servicios abarcan software a medida, aplicaciones a medida, inteligencia artificial, agentes IA, ciberseguridad, pentesting, servicios cloud AWS y Azure, servicios inteligencia de negocio, power bi, y automatización de procesos. Si tu siguiente fase pasa por modelos de machine learning, copilotos y asistentes, consulta nuestros servicios de inteligencia artificial para integrarlos de forma segura y escalable con tus flujos de mensajería.

Conclusión. Fluent Brighter con PostgreSQL te permite implementar outbox e inbox transaccionales, publicaciones y suscripciones unificadas, y un gateway robusto de mensajería con muy poca fricción. La configuración UsingPostgres simplifica el arranque y mantiene la flexibilidad para escenarios avanzados, garantizando consistencia, resiliencia e idempotencia en tus procesos distribuídos.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.

Live Chat