/** * Return config values that may vary by website/store for the given * website. * @param Mage_Core_Model_Website $website * @return array Config values for store id, AMQP username and AMQP password */ public function getWebsiteLevelAmqpConfigurations(Mage_Core_Model_Website $website) { $storeIdPath = $this->_coreConfigMap->getPathForKey(self::STORE_ID_CONFIG_KEY); $usernamePath = $this->_amqpConfigMap->getPathForKey(self::USERNAME_CONFIG_KEY); $passwordPath = $this->_amqpConfigMap->getPathForKey(self::PASSWORD_CONFIG_KEY); $defaultCoreConfig = $this->_coreHelper->getConfigModel(Mage::app()->getStore(0)); $defaultAmqpConfig = $this->_helper->getConfigModel(Mage::app()->getStore(0)); // get website level config values, falling back to any not available to the // website with default store config values return array('store_id' => $website->getConfig($storeIdPath) ?: $defaultCoreConfig->storeId, 'username' => $website->getConfig($usernamePath) ?: $defaultAmqpConfig->username, 'password' => $this->_mageHelper->decrypt($website->getConfig($passwordPath)) ?: $defaultAmqpConfig->password); }
/** * Test connecting to the AMQP server. Will connect to the AMQP server but will * not consume any messages. * @param string $hostname * @param string $username * @param string $password * @return array AJAX response body. Should contain a 'message' => string and 'success' => bool */ public function testConnection($hostname, $username, $password) { try { $this->_validateConfiguration($hostname, $username, $password)->_validateConnection($hostname, $username, $password); } catch (EbayEnterprise_Amqp_Exception $e) { return array('message' => $e->getMessage(), 'success' => false); } catch (Exception $e) { $logData = ['error_message' => $e->getMessage()]; $logMessage = 'Failed to connect to AMQP server with message: {error_message}'; $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__, $logData, $e)); return array('message' => $this->_helper->__(self::UNABLE_TO_VALIDATE), 'success' => false); } return array('message' => $this->_helper->__(self::CONNECTION_SUCCESS), 'success' => true); }
/** * Fetch messages from the queue within the store scope. * @param string $queue Name of the AMQP queue * @param Mage_Core_Model_Store $store * @return self */ protected function _consumeQueue($queue, Mage_Core_Model_Store $store) { $sdk = $this->_helper->getSdkAmqp($queue, $store); $payloads = $sdk->fetch(); // avoid use of foreach to allow exception handling during Current while ($payloads->valid()) { try { $payload = $payloads->current(); } catch (Exception\Payload $e) { // log and skip over any messages that cannot be handled by the SDK $logData = ['queue' => $queue, 'error_message' => $e->getMessage()]; $logMessage = 'Received bad payload on queue {queue}: {error_message}'; $this->_logger->warning($logMessage, $this->_context->getMetaData(__CLASS__, $logData, $e)); $payloads->next(); continue; } $this->_dispatchPayload($payload, $store); $payloads->next(); } return $this; }
/** * Set the value of the "config" to the last timestamp captured from an AMQP * test message. * @return self */ protected function _afterLoad() { $dateTime = $this->_getLastTimestamp(); $value = $dateTime ? $dateTime->format(self::TIMESTAMP_FORMAT) : $this->_helper->__(self::NO_TEST_MESSAGE_RECEIVED); return $this->setValue($value); }
/** * Get the button and scripts contents * @param Varien_Data_Form_Element_Abstract $element * @return string */ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) { $originalData = $element->getOriginalData(); $this->addData(array('button_label' => $this->escapeHtml($this->_amqpHelper->__($originalData['button_label'])), 'html_id' => $element->getHtmlId(), 'ajax_url' => $this->getUrl(self::VALIDATION_URL, array('_current' => true)))); return $this->_toHtml(); }