django应用程序,使发送事务性消息的信号轻松!

jsmsgr的Python项目详细描述


jsmsgr

一种发布事务性消息(短信、电子邮件等)的简单方法,可以为它们的发布提供信号!

要求

此应用程序需要另外两个应用程序才能正常工作:

  • jsm用户服务;
  • 詹戈·斯托普。

两个应用程序都必须已正确配置。它们的配置如下,包括jsmsgrlib:

######################### Django settings file #########################importosINSTALLED_APPS=["...","django_stomp","jsm_user_services","jsmsgr",# add this lib to the INSTALLED_APPS]# django-stomp configSTOMP_SERVER_HOST=os.getenv("STOMP_SERVER_HOST")STOMP_SERVER_PORT=os.getenv("STOMP_SERVER_PORT")STOMP_SERVER_USER=os.getenv("STOMP_SERVER_USER")STOMP_SERVER_PASSWORD=os.getenv("STOMP_SERVER_PASSWORD")STOMP_USE_SSL=os.getenv("STOMP_USE_SSL","True")LISTENER_CLIENT_ID=os.getenv("STOMP_CONSUMPTION_QUEUE")# jsm-user-services configUSER_API_HOST=os.environ.get("USER_API_HOST")

安装

pip install jsmsgr   

设置

为了使用lib,添加以下设置最终信号量目的地名称的env变量:

importosJSMSGR_DESTINATION=os.getenv("JSMSGR_DESTINATION")

使用lib

发布单个消息

fromjsmsgr.apiimportsend_msg_to_usermsg_dict={"msg":"Hello, there, ###_USER_NAME_###","type":"sms","external_id":"external123","callback_mo_destination":"/queue/mo","to_user_id":"a58c4853-2fa5-4891-80c7-f48287dbf403",# user_id to send the msg to}send_msg_to_user(msg_dict)# creates a publisher internallysend_msg_to_user(msg_dict,semaphore_publisher=your_publisher)# user your publisher

发布消息列表

fromjsmsgr.apiimportsend_msgs_to_usermsgs_dict={"msgs":[{"msg":"Hello, there, ###_USER_NAME_###","type":"sms","external_id":"external123","callback_mo_destination":"/queue/mo","to_user_id":"a58c4853-2fa5-4891-80c7-f48287dbf403",# user_id to send the msg to},{"msg":"<strong>Hello world there, ###_USER_NAME_###</strong>","subject":"sub1","type":"email","to_user_id":"a58c4853-2fa5-4891-80c7-f48287dbf403",},{"msg":"<strong>Hello world there once again, ###_USER_NAME_###</strong>","subject":"sub1","type":"email","to_user_id":"a58c4853-2fa5-4891-80c7-f48287dbf403",}]}send_msgs_to_user(msgs_dict)# creates a publisher internallysend_msgs_to_user(msgs_dict,semaphore_publisher=your_publisher)# user your publisher

替换原始邮件中的标记

某些标记用于在原始邮件中执行字符串替换,例如用户名。一些标签 如下所示:

###_USER_NAME_###:替换为用户名(具有给定to_user_id参数值的用户名称)。

示例:

"Hello there, ###_USER_NAME### !"

发送为:

"Hello there, Igor !"

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java JAXB封送字符串,具有xml值,且不转义该值   java ModelMapper转换器不工作   java像HH000412或HCANN000001这样的前缀是什么意思?   验证日期输入修复java。lang.numberformatexception错误   当表具有外键时,java Telosys代码生成失败   如何使所有派生类一起只能实例化一个实例的单例抽象基类?(爪哇)   java如何在非静态服务类中使用广播接收器   java nutch爬虫相对URL问题   使用Jboss DMR下载/保存java附件   Rest模板:无法提取响应:当我们得到xml响应时,没有找到适合响应类型的HttpMessageConverter,没有绑定到JAVA对象   java如何编写可扩展窗格/面板/卡的代码   java是在ITreeViewerListener的treeExpanded()之前调用ContentProvider的getChildren()吗?   java将JComponent添加到小程序窗格   java混淆:使用简单逻辑的Flames程序