jasuwienas/message 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jasuwienas/message

Composer 安装命令:

composer require jasuwienas/message

包简介

Integrates messages queue into Symfony2 project.

README 文档

README

Integrates messages (mailer, sms api) into Symfony project.

Installation

Add as composer dependency:

composer require jasuwienas/message

Add in application kernel:

class AppKernel extends Kernel
{
    public function registerBundles()
    {
    //...
    $bundles[] = new \Jasuwienas\MessageBundle\MessageBundle();
    return $bundles;
    }
}

Create message queue object entity

it should extend class \Jasuwienas\MessageBundle\Model\MessageQueue. For example:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use DateTime;
use Jasuwienas\MessageBundle\Service\QueueManagerService;
use Jasuwienas\MessageBundle\Model\MessageQueue as BaseMessageQueue;

/**
 * MessageQueue
 *
 * @ORM\Table("message_queue")
 * @ORM\Entity
 * @ORM\HasLifecycleCallbacks()
 */
class MessageQueue extends BaseMessageQueue
{

    const STATUS_NEW = 0;
    const STATUS_PROCESSED = 1;
    const STATUS_SUCCESS = 2;
    const STATUS_TRY_AGAIN = 3;
    const STATUS_ERROR = 4;

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @var string
     *
     * @ORM\Column(name="adapter", type="string", nullable=false, length=32, options={"comment": "Name of the sender which will process this message"})
     */
    protected $adapter;

    /**
     * @var string
     *
     * @ORM\Column(name="recipient", type="text", nullable=false, options={"comment": "Recipient of the message (email for MailSender and phone number for SMSSender)"})
     */
    protected $recipient;

    /**
     * @var string
     *
     * @ORM\Column(name="title", type="text", nullable=true, options={"comment": "Message title"})
     */
    protected $title;

    /**
     * @var string
     *
     * @ORM\Column(name="body", type="text", nullable=true, options={"comment": "Message body"})
     */
    protected $body;

    /**
     * @var string
     *
     * @ORM\Column(name="plan_body", type="text", nullable=true, options={"comment": "Body of the message with special characters removed"})
     */
    protected $plainBody;

    /**
     * @var int
     *
     * @ORM\Column(name="status", type="integer", nullable=false, options={"default":0, "comment": "Message sending status. 0 - new, awaiting, 1 - processed, 2 - sent, 3 - sending failed, waiting for next attempt, 4 - error"})
     */
    protected $status = 0;

    /**
     * @var string
     *
     * @ORM\Column(name="error", type="text", nullable=true, options={"comment": "Error message"})
     */
    protected $error;

    /**
     * @var DateTime
     *
     * @ORM\Column(name="send_at", type="datetime", nullable=true, options={"comment": "Date time of sending this message"})
     */
    protected $sendAt;

    /**
     * @var int
     *
     * @ORM\Column(name="attempts", type="integer", nullable=true, options={"default": 0, "comment": "Number of attempts to send this message"})
     */
    protected $attempts = 0;

    /**
     * @var string
     *
     * @ORM\Column(name="content_type", type="text", nullable=true, options={"comment": "Entity connect with this message - name"})
     */
    protected $contentType;

    /**
     * @var int
     *
     * @ORM\Column(name="content_id", type="integer", nullable=true, options={"comment": "Entity connect with this message - id"})
     */
    protected $contentId;

    /**
     * @var DateTime
     *
     * @ORM\Column(name="created_at", type="datetime", nullable=true)
     */
    protected $createdAt;

    /**
     * @var DateTime
     *
     * @ORM\Column(name="updated_at", type="datetime", nullable=true)
     */
    protected $updatedAt;

    /**
     * @var DateTime
     *
     * @ORM\Column(name="send_at", type="datetime", nullable=true)
     */
    protected $sendAt;

    /**
     * @var int
     *
     * @ORM\Column(name="attempts", type="smallint", length=1, options={"comment" = "counts number of sending attempts"}, nullable=false)
     */
    protected $attempts = 0;

	 /**
     * @var array
     *
     * @ORM\Column(name="attachments", type="json_array", nullable=true, options={"comments": "List of attachments (paths)"})
     */
    protected $attachments = [];

    /**
     * Priority - higher priority messages will be send sooner
     *
     * @var int
     * @ORM\Column(name="priority", type="integer", nullable=false, options={"default": 0, "comments": "Message sending priority - the biggest priority the sooner mail will be send"})
     */
    protected $priority = 0;

    /**
     * @ORM\PrePersist
     * @ORM\PreUpdate
     */
    public function prePersist()
    {
        $now = new Datetime;
        if(!$this->getCreatedAt()) {
            $this->setCreatedAt($now);
        }
        if(!$this->getSendAt()) {
            $this->setSendAt($now);
        }
        $this->setUpdatedAt($now);
    }

    /**
     * Set created at
     *
     * @param DateTime $createdAt
     * @return $this
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;

        return $this;
    }

    /**
     * Get created at
     *
     * @return DateTime
     */
    public function getCreatedAt()
    {
        return $this->createdAt;
    }

    /**
     * Set updated at
     *
     * @param DateTime $updatedAt
     * @return $this
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

    /**
     * Get updated at
     *
     * @return DateTime
     */
    public function getUpdatedAt()
    {
        return $this->updatedAt;
    }

}

Set entity class name in your application config.yml file.

For example:

message:
    queue_object_class: App\Entity\MessageQueue

Configuring Smtp mail sender.

Configure base smtp connection (https://symfony.com/doc/current/email.html)

IMPORTANT Remove spool from your config (https://symfony.com/doc/current/email/spool.html). You should remove line

    spool: { type: 'memory' }

if it exists in your configuration

Add

message:
    smtp_mailer_user: test@test.com

to your config.yml (config/packages/message.yaml in symfony 4).

Replace test@test.com with message sender user

Configuring Freshmail

add

message:
    freshmail_api_host:         'https://api.freshmail.com/'
    freshmail_api_prefix:       'rest/'
    freshmail_api_api_key:      API_KEY
    freshmail_api_secret_key:   SECRET_KEY

to your config.yml (config/packages/message.yaml in symfony 4).

Replace API_KEY and SECRET_KEY with your frashmail keys.

Configuring SMSApi

Add

message:
    sms_api_host: 'https://api.smsapi.pl/sms.do'
    sms_api_access_token: API_TOKEN

to your config.yml (config/packages/message.yaml in symfony 4).

Replace API_TOKEN with your sms_api access token.

Adding messages to queue:

$this->get('message.queue_manager')->push( 'jasuwienas@gmail.com', 'Test title', 'Test content', new DateTime(), 'smtp' );

Message sending command:

Symfony < 3.4

php app/console messages:send

Symfony 4+

bin/console messages:send

jasuwienas/message 适用场景与选型建议

jasuwienas/message 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.42k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 09 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「message mail sms symfony2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jasuwienas/message 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jasuwienas/message 我们能提供哪些服务?
定制开发 / 二次开发

基于 jasuwienas/message 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.42k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-09-03