
Product
Announcing Bun and vlt Support in Socket
Bringing supply chain security to the next generation of JavaScript package managers
@apogeelabs/hoppity-subscriptions
Advanced tools
Subscription management middleware for hoppity - a Rascal broker configuration library.
This plugin provides middleware for setting up subscription handlers in a hoppity pipeline. It validates subscription handlers against the broker topology and automatically wires up message listeners when the broker is created.
pnpm add @apogeelabs/hoppity-subscriptions
import hoppity from "@apogeelabs/hoppity";
import { withSubscriptions } from "@apogeelabs/hoppity-subscriptions";
// Define your topology with subscriptions
const topology = {
vhosts: {
"/": {
subscriptions: {
"user-events": {
queue: "user-events-queue",
// ... other subscription config
},
"order-events": {
queue: "order-events-queue",
// ... other subscription config
},
},
},
},
};
// Define your handlers
const handlers = {
"user-events": async (message, content, ackOrNack, broker) => {
console.log("Processing user event:", content);
// Your handler logic here
ackOrNack();
},
"order-events": (message, content, ackOrNack, broker) => {
console.log("Processing order event:", content);
// Your handler logic here
ackOrNack();
},
};
// Create broker with subscription middleware
const broker = await hoppity.withTopology(topology).use(withSubscriptions(handlers)).build();
type SubscriptionHandler = (
message: Message,
content: any,
ackOrNackFn: AckOrNack,
broker: BrokerAsPromised
) => Promise<void> | void;
The middleware validates:
If validation fails, the pipeline fails with a descriptive error message including:
The middleware provides automatic error handling:
The middleware stores validated subscription information in the middleware context:
// Access validated subscriptions from context
context.data.validatedSubscriptions; // Array of subscription names that passed validation
withSubscriptions(handlers: SubscriptionHandlers): MiddlewareFunctionCreates a middleware function that sets up subscription handlers.
handlers: Object mapping subscription names to handler functionsA middleware function that can be used in the hoppity pipeline.
validateSubscriptionHandlers(topology: BrokerConfig, handlers: SubscriptionHandlers): ValidationResultValidates subscription handlers against the broker topology. This function is exported for standalone validation if needed.
topology: The broker topology configurationhandlers: The subscription handlers objectA ValidationResult object with detailed validation information.
SubscriptionHandlerHandler function signature for processing subscription messages.
SubscriptionHandlersType for the handlers object: Record<string, SubscriptionHandler>
ValidationResultResult object from validation with detailed error information:
interface ValidationResult {
isValid: boolean;
missingSubscriptions: string[];
availableSubscriptions: string[];
invalidHandlers: string[];
duplicateHandlers: string[];
errorMessage?: string;
}
This plugin integrates seamlessly with the hoppity middleware pipeline:
The middleware follows hoppity's fail-fast pattern and provides comprehensive logging throughout the process.
# Install dependencies
pnpm install
# Build the package
pnpm build
# Run tests
pnpm test
# Run tests in watch mode
pnpm test:watch
# Lint code
pnpm lint
# Format code
pnpm format
ISC
FAQs
Subscription management for hoppity
We found that @apogeelabs/hoppity-subscriptions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Bringing supply chain security to the next generation of JavaScript package managers

Product
A safer, faster way to eliminate vulnerabilities without updating dependencies

Product
Reachability analysis for Ruby is now in beta, helping teams identify which vulnerabilities are truly exploitable in their applications.