use of com.netflix.conductor.core.events.queue.ObservableQueue in project conductor by Netflix.
the class Event method start.
@Override
public void start(Workflow workflow, Task task, WorkflowExecutor provider) {
Map<String, Object> payload = new HashMap<>(task.getInputData());
payload.put("workflowInstanceId", workflow.getWorkflowId());
payload.put("workflowType", workflow.getWorkflowName());
payload.put("workflowVersion", workflow.getWorkflowVersion());
payload.put("correlationId", workflow.getCorrelationId());
String payloadJson;
try {
payloadJson = objectMapper.writeValueAsString(payload);
} catch (JsonProcessingException e) {
String msg = String.format("Error serializing JSON payload for task: %s, workflow: %s", task.getTaskId(), workflow.getWorkflowId());
throw new ApplicationException(INTERNAL_ERROR, msg);
}
Message message = new Message(task.getTaskId(), payloadJson, task.getTaskId());
ObservableQueue queue = getQueue(workflow, task);
if (queue != null) {
queue.publish(Collections.singletonList(message));
logger.debug("Published message:{} to queue:{}", message.getId(), queue.getName());
task.getOutputData().putAll(payload);
if (isAsyncComplete(task)) {
task.setStatus(Status.IN_PROGRESS);
} else {
task.setStatus(Status.COMPLETED);
}
} else {
task.setReasonForIncompletion("No queue found to publish.");
task.setStatus(Status.FAILED);
}
}
use of com.netflix.conductor.core.events.queue.ObservableQueue in project conductor by Netflix.
the class AMQPModule method getQueues.
@Provides
public Map<Task.Status, ObservableQueue> getQueues(Configuration config) {
String stack = "";
if (config.getStack() != null && config.getStack().length() > 0) {
stack = config.getStack() + "_";
}
final boolean useExchange = config.getBooleanProperty("workflow.listener.queue.useExchange", USE_EXCHANGE_BY_DEFAULT);
Task.Status[] statuses = new Task.Status[] { Task.Status.COMPLETED, Task.Status.FAILED };
Map<Task.Status, ObservableQueue> queues = new HashMap<>();
for (Task.Status status : statuses) {
String queueName = config.getProperty("workflow.listener.queue.prefix", config.getAppId() + "_amqp_notify_" + stack + status.name());
final ObservableQueue queue = new AMQPObservableQueue.Builder(config).build(useExchange, queueName);
queues.put(status, queue);
}
return queues;
}
use of com.netflix.conductor.core.events.queue.ObservableQueue in project conductor by Netflix.
the class QueueManager method update.
private void update(Map<String, Object> externalIdMap, Map<String, Object> output, Status status) throws Exception {
Map<String, Object> outputMap = new HashMap<>();
outputMap.put("externalId", objectMapper.writeValueAsString(externalIdMap));
outputMap.putAll(output);
Message msg = new Message(UUID.randomUUID().toString(), objectMapper.writeValueAsString(outputMap), null);
ObservableQueue queue = queues.get(status);
if (queue == null) {
throw new IllegalArgumentException("There is no queue for handling " + status.toString() + " status");
}
queue.publish(Arrays.asList(msg));
}
use of com.netflix.conductor.core.events.queue.ObservableQueue in project conductor by Netflix.
the class AMQPEventQueueProviderTest method testAMQPEventQueueProvider_defaultconfig_exchange.
@Test
public void testAMQPEventQueueProvider_defaultconfig_exchange() {
String exchangestring = "amqp_exchange:myExchangeName?exchangeType=topic&routingKey=test&deliveryMode=2";
Mockito.when(config.getProperty(Mockito.anyString(), Mockito.anyString())).thenAnswer(invocation -> invocation.getArgument(1));
Mockito.when(config.getBooleanProperty(Mockito.anyString(), Mockito.anyBoolean())).thenAnswer(invocation -> invocation.getArgument(1));
Mockito.when(config.getIntProperty(Mockito.anyString(), Mockito.anyInt())).thenAnswer(invocation -> invocation.getArgument(1));
AMQPEventQueueProvider eventqProvider = new AMQPEventQueueProvider(config, true);
ObservableQueue queue = eventqProvider.getQueue(exchangestring);
Assert.assertNotNull(queue);
Assert.assertEquals(exchangestring, queue.getName());
Assert.assertEquals(AMQPConstants.AMQP_EXCHANGE_TYPE, queue.getType());
}
Aggregations