Skip to content

Network Swiftlet

Overview

The Network Swiftlet (sys$net) manages all network connectivity for the SwiftMQ router, including TCP and intra-VM connections. It is responsible for creating, monitoring, and closing network connections, handling both incoming and outgoing connections, and collecting connection throughput statistics.

Features

TCP Listener and Connector Management

The Network Swiftlet manages both TCP listeners (for accepting inbound connections) and TCP connectors (for establishing outbound connections) using the Netty framework. Listeners and connectors are dynamically created and started based on configuration and runtime conditions. Each listener or connector is associated with a specific Swiftlet and can be started immediately or delayed until the router is fully initialized. The Swiftlet supports both plain and TLS-encrypted connections, with TLS enabled by specifying the appropriate socket factory class. Listeners enforce access control via allowed hostnames (if DNS resolution is enabled), and connectors can be configured to retry on failure.

TLS/SSL Support

TLS encryption is supported for both listeners and connectors. The SSL context is configured via Java system properties, supporting both keystore-based and PEM file-based setups. Client authentication can be enforced by setting the swiftmq.tls.clientauth.enabled system property to true.

Delayed Start Mechanism

Listeners and connectors can be started in a delayed fashion, allowing the router to fully initialize before network endpoints are activated. This is particularly important in high-availability scenarios or when startup order matters.

Configuration Example:

<swiftlet name="sys$net" dns-resolve-enabled="true" reuse-serversockets="false"/>

Connection Management and Monitoring

All active connections are tracked by the ConnectionManager, which maintains a list of current connections. Each connection is represented as an entity under the usage entity list, storing metadata such as the attached Swiftlet, connection time, and throughput statistics. The Swiftlet provides mechanisms to add and remove connections, both individually and in bulk (e.g., during shutdown).

Throughput Statistics Collection

The Swiftlet periodically collects input and output throughput (in KB/s) for each connection. The collection interval is configurable via the collect-interval property. Throughput statistics are reset after each collection cycle and are made available for monitoring and management.

Connection Lifecycle Handling

Connections are automatically closed and removed when they become inactive, encounter errors, or are explicitly closed by management operations. The Swiftlet ensures proper cleanup and resource release for all connection types.

Configuration Example:

<swiftlet name="sys$net" collect-interval="5000"/>

Intra-VM Connection Support

The Network Swiftlet supports intra-VM (in-process) connections, allowing different Swiftlets within the same JVM to communicate efficiently without network overhead. Intra-VM listeners and connections are managed separately from TCP endpoints, but follow a similar lifecycle and monitoring model.

Intra-VM Listener Registration

Swiftlets can register intra-VM listeners, which are then available for other Swiftlets to connect to within the same JVM. The scheduler manages the mapping and lifecycle of these listeners.

Chunked Data Handling

Intra-VM connections use chunked data streams to efficiently transfer messages, with chunk completion triggering data delivery to the appropriate handler.

Zombi Connection Detection and Timeout

The Swiftlet includes a mechanism to detect and close zombi (inactive or half-open) connections. If a connection does not become active within the configured zombi-connection-timeout period, it is automatically closed to prevent resource leakage and potential denial-of-service conditions.

Configuration Example:

<swiftlet name="sys$net" zombi-connection-timeout="30000"/>

Maximum Chunk Size Enforcement

To protect the router from excessively large messages, the Swiftlet enforces a maximum chunk size for incoming network data. If a received message exceeds the configured max-chunk-size, the connection is closed and an error is logged. This provides a router-wide limit on the size of individual network messages.

Configuration Example:

<swiftlet name="sys$net" max-chunk-size="1048576"/>

Selector Task Thread Pool Configuration

The number of selector tasks (network I/O threads) used by the Swiftlet is configurable via the number-selector-tasks property. This allows tuning for multi-processor machines and high-throughput scenarios. Changing this value requires a router reboot.

Configuration Example:

<swiftlet name="sys$net" number-selector-tasks="20"/>

Configuration Guide

Enable DNS Resolution for Incoming Connections

Enable DNS name resolution for all incoming and outgoing network connections, allowing access control by hostname and improved logging.

  1. Edit the routerconfig.xml file.
  2. Set the dns-resolve-enabled attribute to true on the sys$net swiftlet.
  3. Restart the router if required.
<swiftlet name="sys$net" dns-resolve-enabled="true"/>

Set a Maximum Incoming Message Size

Limit the size of incoming network messages to prevent resource exhaustion or denial-of-service attacks.

  1. Edit the routerconfig.xml file.
  2. Set the max-chunk-size attribute (in bytes) to the desired maximum on the sys$net swiftlet.
  3. Restart the router if required.
<swiftlet name="sys$net" max-chunk-size="2097152"/>

Adjust Throughput Statistics Collection Interval

Change how frequently the Swiftlet collects and reports connection throughput statistics.

  1. Edit the routerconfig.xml file.
  2. Set the collect-interval attribute (in milliseconds) to the desired value on the sys$net swiftlet.
  3. No restart is required for this change.
<swiftlet name="sys$net" collect-interval="2000"/>

Configure Zombi Connection Timeout

Automatically close connections that remain inactive for too long to prevent resource leaks.

  1. Edit the routerconfig.xml file.
  2. Set the zombi-connection-timeout attribute (in milliseconds) to the desired timeout on the sys$net swiftlet.
  3. No restart is required for this change.
<swiftlet name="sys$net" zombi-connection-timeout="60000"/>

Configuration Reference

The top-level entity in routerconfig.xml is <swiftlet name="sys$net">.

<swiftlet name="sys$net"> Properties

These properties are attributes of the <swiftlet name="sys$net"> entity.

Parameter Type Default Mandatory Reboot Required Description
collect-interval Long 1000 No No Throughput Collect Interval
zombi-connection-timeout Long 0 No No Zombi-Connection Timeout
dns-resolve-enabled Boolean false No No Resolve DNS Names during Connect
reuse-serversockets Boolean true No No Re-Use Server Sockets
number-selector-tasks Integer 10 No Yes Number Selector Tasks. Might be increased for Multi-Processor Machines. (min: 4)
max-chunk-size Long -1 No No Maximum size of a network chunk (chunk = message in JMS) to limit the incoming message size router-wide.
<swiftlet name="sys$net" collect-interval="1000" zombi-connection-timeout="0" dns-resolve-enabled="false" reuse-serversockets="true" number-selector-tasks="10" max-chunk-size="-1"/>