comsave/safe-salesforce-saver-bundle 问题修复 & 功能扩展

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

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

comsave/safe-salesforce-saver-bundle

Composer 安装命令:

composer require comsave/safe-salesforce-saver-bundle

包简介

Allows you to save your objects to Salesforce safely

README 文档

README

Release Travis Test Coverage

About

With this bundle you can stop worrying about your data getting lost when trying to save information to Salesforce. The SafeSalesforceSaver will take the objects you give it and place them in a queue. The items are taken out of the queue one by one to prevent Salesforce from getting overwhelmed if you decide to save hundreds (or thoussands) of objects at once. If an exception does occur during the save process, rabbit will simply retry the save a few moments later while logging the error away so you can debug what went wrong.

Installation

$ composer require comsave/safe-salesforce-saver-bundle

Depending on your Symfony version you either have to register the bundle in app/AppKernel.php (Symfony 3.4 and lower):

public function registerBundles()
{
    $bundles = [
        new Comsave\SafeSalesforceSaverBundle\ComsaveSafeSalesforceSaverBundle(),
    ];

    return $bundles;
}

Or (Symfony 4.0 and higher) in your config/bundles.php:

return [
     Comsave\SafeSalesforceSaverBundle\ComsaveSafeSalesforceSaverBundle::class => ['all' => true],
];

Usage

To get this bundle to work you will have to start the queues in your rabbit client. To do this you have to add the following configuration to your projects config.yml:

old_sound_rabbit_mq:
    producers:
        sss_async_processor:
            class: Comsave\SafeSalesforceSaverBundle\Producer\AsyncSfSaverProducer
            connection: default
            exchange_options:
                name: 'sss_async_queue'
                type: direct
    consumers:
        sss_async_processor:
            connection: default
            exchange_options:
                name: 'sss_async_queue'
                type: direct
            queue_options:
                name: 'sss_async_queue'
            qos_options:
                prefetch_size: 0
                prefetch_count: 1
                global: false
            callback: Comsave\SafeSalesforceSaverBundle\Consumers\AsyncSfSaveConsumer
    rpc_clients:
        parallel:
            connection: default
            expect_serialized_response: false
    rpc_servers:
        safe_salesforce_saver_server:
            connection: default
            callback: Comsave\SafeSalesforceSaverBundle\Consumers\SafeSalesforceSaverServer
            qos_options: { prefetch_size: 0, prefetch_count: 1, global: false }
            queue_options: { name: sss_rpc_queue, durable: true, auto_delete: false }

It is important that you do not change the names of the queues as this could lead to issues. The above configuration assumes that you already have the default configuration for rabbitMQ set up. If not, please refer to the readme file of the rabbit bundle on github.

In order to actually save your objects to Salesforce they have to be annotated in the right way. See the mapper bundle on github.

When you have updated your configuration and models you can save them in two different ways. Synchronous or a-synchronous:

<?php

use Comsave\SafeSalesforceSaverBundle\Services\SafeSalesforceSaver;

class ObjectSaver
{
    /** @var SafeSalesforceSaver */
    private $safeSalesforceSaver;

    /**
     * @param SafeSalesforceSaver $safeSalesforceSaver
     */
    public function __construct(SafeSalesforceSaver $safeSalesforceSaver)
    {
        $this->safeSalesforceSaver = $safeSalesforceSaver;
    }

    // This way of saving will wait for the save result from Salesforce. This means that you can immediately access the newly inserted ID after Salesforce saved the record.
    public function saveSingle(Object $object): string
    {
        $this->safeSalesforceSaver->save($object);

        return $object->getId();
    }
    
    // This function lets you save multiple objects at once. Simply put all the objects you want to save in an array and pass it to the SafeSalesforceSaver. 
    public function saveMultiple(Object $object, Object $object2, Object $object3): array
    {
        $this->safeSalesforceSaver->save([$object, $object2, $object3]);

        return [$object->getId(), $object2->getId(), $object3->getId()];
    }

    // If you do not want to wait for the result you can simply put your object into the queue and continue with the rest of your code. This is recommended if you don't need the ID or if you don't need a confirmation that the save succeeded.
    public function aSyncSaveSingle(Object $object): void
    {
        $this->safeSalesforceSaver->aSyncSave($object);
    }

    // As with the other save function, it is also possible to save multiple objects to Salesforce at once without waiting for the response.
    public function aSyncSaveMultiple(Object $object, Object $object2, Object $object3): void
    {
        $this->safeSalesforceSaver->aSyncSave([$object, $object2, $object3]);
    }
}

comsave/safe-salesforce-saver-bundle 适用场景与选型建议

comsave/safe-salesforce-saver-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 418 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 comsave/safe-salesforce-saver-bundle 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-12