Xinboo
Xinboo

.NET Developer

C#


用 MQTTnet 的 ManagedMqttClient 创建带自动重连的 MQTT 客户端

Imagine building an IoT system where the network is as unreliable as a dial-up connection in the 90s. How do you ensure your sensors talk to each other without constant manual intervention? The answer lies in shifting from basic MQTT clients to intelligent, managed architectures like ManagedMqttClient. This approach automates the tedious work of reconnection and message queuing, allowing developers to focus on logic rather than infrastructure maintenance. But beyond convenience, it forces us to confront the core mechanics of message delivery: Quality of Service (QoS), CleanSession flags, and Retain messages. These are not just technical settings; they are philosophical choices about reliability versus efficiency. QoS 0 offers speed at the cost of certainty, while QoS 2 guarantees perfection but demands a heavy performance toll. Where is the sweet spot for your application? Is it worth sacrificing latency to ensure that every single command is executed exactly once? The CleanSession par...--AI Generated

.NET C# MQTTnet ManagedMqttClient MQTT IoT

用 .NET Framework 4.7.2 手搓一个 IoC 容器

Dependency Injection is often treated as a black box in modern .NET development, where services are magically wired together without understanding the underlying mechanics. This exploration demystifies the Inversion of Control container by stripping away the complexity of established frameworks like Autofac or Microsoft.Extensions.DependencyInjection to reveal the core logic that powers them. At its heart, an IoC container performs three fundamental operations: registration, resolution, and lifecycle management. Registration maps interfaces to concrete implementations, while resolution recursively traverses dependency graphs, instantiating objects through reflection until all leaf nodes are resolved. The true magic lies in this recursive process, where the container automatically fulfills constructor arguments by resolving their own dependencies, creating a seamless chain of object creation that eliminates manual instantiation code. Lifecycle management adds another layer of control, ...--AI Generated

.NET IoC Dependency Injection C# Inversion of Control DI Container

StackExchange.Redis 的断连坑

Redis, the ubiquitous in-memory data store, promises lightning-fast performance and seamless integration for modern applications. Yet, beneath its efficient surface lies a labyrinth of connectivity pitfalls that can silently cripple your system. Consider the StackExchange.Redis client: a default configuration choice regarding abortConnect can turn a minor network hiccup into a permanent application deadlock, forcing unnecessary restarts and disrupting service availability. This is not merely a technical oversight but a fundamental misunderstanding of how connection states persist under pressure. What happens when the invisible hand of TCP retries dictates your application's fate? On Linux systems, kernel parameters like tcp_retries2 can enforce a agonizing fifteen-minute silence after a Redis node restart, leaving clients stranded in a state of limbo while infrastructure attempts to recover. This delay is not a bug but a feature of the underlying protocol stack, revealing how deeply ou...--AI Generated

.NET Redis C# StackExchange.Redis Troubleshooting BestPractices

  • 1