dongshu9458 2013-03-06 21:14
浏览 70
已采纳

数据被覆盖,rabbitmq优秀

I am using rabbitmq queue for getting data from a controller and then consumer service process the data and produces excel sheet using php-excel.

The issue i am facing is that the data is getting overwritten in excel sheets if only one consumer is run. If i run multiple consumers, the issue is mostly resolved.

I am using direct as rabbitmq type and luiggio excel bundle for symfony2.

Did anyone ever has a similar problem? Any hints about possible issue are welcome.

//part of consumer code

public function execute(AMQPMessage $msg)
    {
        $data = array();
        $data = unserialize($msg->body);

        if ($data['type'] == 'sometype') {
                $this->excel->excelObj->getProperties()->setCreator("something");
                $value = $this->excel->excelObj->setActiveSheetIndex(0);
                $value->setCellValue('A1', 'Some Number');
                $value->setCellValue('B1', 'Some Other Number');
                $incr = 2;
                foreach ($data['somedata'] as $datum) {
                  value->setCellValue('A'.$incr, $datum['that_number']);
                  value->setCellValue('B'.$incr, $datum['that_number']);
                }
        } else if ($data['type'] == 'sometype2') {
                $this->excel->excelObj->getProperties()->setCreator("something");
                $value = $this->excel->excelObj->setActiveSheetIndex(0);
                $value->setCellValue('A1', 'Some Number2');
                $incr = 2;
                foreach ($data['somedata'] as $datum) {
                  value->setCellValue('A'.$incr, $datum['that_number']);
                }
        }

        $this->excel->excelObj->getActiveSheet()->setTitle('Simple');
        $this->excel->excelObj->setActiveSheetIndex(0);
        $tempName = $data['type'] .microtime(). '.xls';
        $this->excel->getStreamWriter()->write('/tmp/'.$tempName);
    }
  • 写回答

2条回答 默认 最新

  • duanchou6534 2013-10-09 19:10
    关注

    The issue was with the PHP excel object being created.

    Finally resolved it by initiating/resetting the excel object forcefully after one excel sheet is generated.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效