connection = new AMQPStreamConnection( self::RABBIT_MQ_HOST, self::RABBIT_MQ_PORT, self::RABBIT_MQ_USER, self::RABBIT_MQ_PASSWORD ); $this->channel = $this->connection->channel(); } catch ( Exception $ex ) { return new WP_Error( 'stream_connection_error', $ex->getMessage() ); } } public function send( $data ) { if ( ! function_exists( 'bcadd' ) ) { return new WP_Error( 'stream_bcadd_function', esc_html__( 'Function bcadd is not defined, instal PHP module "php-bcmath".', Core::SLUG ) ); } $status = $this->open_connection(); if ( is_wp_error( $status ) ) { return $status; } try { $this->channel->queue_declare( 'reports', false, true, false, false ); $message = new AMQPMessage( wp_json_encode( $data ), array( 'delivery_mode' => 2 ) ); $this->channel->basic_publish( $message, '', 'reports' ); $this->close_connection(); } catch ( Exception $ex ) { return new WP_Error( 'stream_message_error', $ex->getMessage() ); } return true; } public function close_connection() { $this->channel->close(); $this->connection->close(); } }