Skip to content

消息中间件

功能介绍#

消息中间件插件用于平台引入消息中间件(如Artemis,kafka等)与第三方系统进行消息通信(如通知数据)

实现思路#

开发者在开发消息中间件插件时,仅需继承消息中间件插件基类并完成数据写入过程,平台已提供消息存储模型(可扩展),且在基类中提供消息存储方法:

基类定义#

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

评论