Skip to content

MessageMiddleware

Features#

Message middleware plug -in for platform introduction message middle parts(Such as Artemis,KAFKA etc.)Communication with a third -party system(If the notification data)

Implementation#

When developing a message in the middleware plug -in,Only inherit the message of the message intercding and complete the data writing process,The platform has provided message storage model(Scalable),And provide message storage methods in the base class:

Foundation definition#

arkid.core.extension.message.MessageExtension (Extension) #

Source code in arkid/core/extension/message.py
class MessageExtension(Extension):

    TYPE = "message"

    @property
    def type(self):
        return MessageExtension.TYPE

    def load(self):
        super().load()

    def save_message(self,tenant:Tenant,user:User,source:TenantExtensionConfig,title:str,content:str,**kwargs):
        """保存消息

        Args:
            tenant (Tenant): 租户
            user (User): 用户
            source (TenantExtensionConfig): 来源
            title (str): 标题
            content (str): 内容
        """
        try:
            message = Message(
                tenant=tenant,
                user=user,
                source=source,
                title=title,
                content=content
            )

            message.save()
        except Exception as err:
            logger.error(err)
            return False, ErrorCode.MESSAGE_SAVE_FAILED

        return True,None

load(self) #

抽象方法,插件加载的入口方法

Source code in arkid/core/extension/message.py
def load(self):
    super().load()

save_message(self, tenant, user, source, title, content, **kwargs) #

保存消息

Parameters:

Name Type Description Default
tenant Tenant

租户

required
user User

用户

required
source TenantExtensionConfig

来源

required
title str

标题

required
content str

内容

required
Source code in arkid/core/extension/message.py
def save_message(self,tenant:Tenant,user:User,source:TenantExtensionConfig,title:str,content:str,**kwargs):
    """保存消息

    Args:
        tenant (Tenant): 租户
        user (User): 用户
        source (TenantExtensionConfig): 来源
        title (str): 标题
        content (str): 内容
    """
    try:
        message = Message(
            tenant=tenant,
            user=user,
            source=source,
            title=title,
            content=content
        )

        message.save()
    except Exception as err:
        logger.error(err)
        return False, ErrorCode.MESSAGE_SAVE_FAILED

    return True,None

评论