Skip to main content

CheckForbiddenHook

Trait CheckForbiddenHook 

Source
pub trait CheckForbiddenHook: Send + Sync {
    // Required methods
    fn hook_name(&self) -> &'static str;
    fn check_forbidden(
        &self,
        context: &CheckForbiddenContext<'_>,
    ) -> ClientResult<()>;
}
Expand description

Hook for checking forbidden message sending operations.

This trait allows custom validation logic to be executed before messages are sent. Implementations can inspect the message context and reject operations that violate business rules or security policies.

All implementations must be Send + Sync to support concurrent message sending in multi-threaded producer environments.

§Examples

ⓘ
use rocketmq_client::CheckForbiddenContext;
use rocketmq_client::CheckForbiddenHook;
use crate::ClientResult;

struct RegionValidator;

impl CheckForbiddenHook for RegionValidator {
    fn hook_name(&self) -> &'static str {
        "RegionValidator"
    }

    fn check_forbidden(&self, context: &CheckForbiddenContext) -> ClientResult<()> {
        if let Some(broker_addr) = &context.broker_addr {
            if broker_addr.contains("forbidden-region") {
                return Err("Cannot send to forbidden region".into());
            }
        }
        Ok(())
    }
}

Required Methods§

Source

fn hook_name(&self) -> &'static str

Returns the unique name of this hook.

The name is used for logging and diagnostic purposes.

Source

fn check_forbidden( &self, context: &CheckForbiddenContext<'_>, ) -> ClientResult<()>

Validates whether a message send operation should be allowed.

§Errors

Returns an error if the operation should be rejected based on the context.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§