django应用程序,使发送事务性消息的信号轻松!
jsmsgr的Python项目详细描述
jsmsgr
一种发布事务性消息(短信、电子邮件等)的简单方法,可以为它们的发布提供信号!
要求
此应用程序需要另外两个应用程序才能正常工作:
- jsm用户服务;
- 詹戈·斯托普。
两个应用程序都必须已正确配置。它们的配置如下,包括jsmsgr
lib:
######################### 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 !"