use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.
the class AMQPObservableQueue method ack.
@Override
public List<String> ack(List<Message> messages) {
final List<String> processedDeliveryTags = new ArrayList<>();
for (final Message message : messages) {
try {
logger.info("ACK message with delivery tag {}", message.getReceipt());
getOrCreateChannel().basicAck(Long.valueOf(message.getReceipt()), false);
// Message ACKed
processedDeliveryTags.add(message.getReceipt());
} catch (final IOException e) {
logger.error("Cannot ACK message with delivery tag {}", message.getReceipt(), e);
}
}
return processedDeliveryTags;
}
use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.
the class NATSAbstractQueue method observe.
@Override
public Observable<Message> observe() {
logger.info("Observe invoked for queueURI " + queueURI);
observable = true;
mu.lock();
try {
subscribe();
} finally {
mu.unlock();
}
Observable.OnSubscribe<Message> onSubscribe = subscriber -> {
Observable<Long> interval = Observable.interval(100, TimeUnit.MILLISECONDS, scheduler);
interval.flatMap((Long x) -> {
List<Message> available = new LinkedList<>();
messages.drainTo(available);
if (!available.isEmpty()) {
AtomicInteger count = new AtomicInteger(0);
StringBuilder buffer = new StringBuilder();
available.forEach(msg -> {
buffer.append(msg.getId()).append("=").append(msg.getPayload());
count.incrementAndGet();
if (count.get() < available.size()) {
buffer.append(",");
}
});
logger.info(String.format("Batch from %s to conductor is %s", subject, buffer.toString()));
}
return Observable.from(available);
}).subscribe(subscriber::onNext, subscriber::onError);
};
return Observable.create(onSubscribe);
}
use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.
the class NATSAbstractQueue method onMessage.
void onMessage(String subject, byte[] data) {
String payload = new String(data);
logger.info(String.format("Received message for %s: %s", subject, payload));
Message dstMsg = new Message();
dstMsg.setId(NUID.nextGlobal());
dstMsg.setPayload(payload);
messages.add(dstMsg);
}
use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.
the class SQSObservableQueue method receiveMessages.
@VisibleForTesting
List<Message> receiveMessages() {
try {
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest().withQueueUrl(queueURL).withVisibilityTimeout(visibilityTimeoutInSeconds).withMaxNumberOfMessages(batchSize);
ReceiveMessageResult result = client.receiveMessage(receiveMessageRequest);
List<Message> messages = result.getMessages().stream().map(msg -> new Message(msg.getMessageId(), msg.getBody(), msg.getReceiptHandle())).collect(Collectors.toList());
Monitors.recordEventQueueMessagesProcessed(QUEUE_TYPE, this.queueName, messages.size());
return messages;
} catch (Exception e) {
logger.error("Exception while getting messages from SQS", e);
Monitors.recordObservableQMessageReceivedErrors(QUEUE_TYPE);
}
return new ArrayList<>();
}
use of com.netflix.conductor.core.events.queue.Message in project conductor by Netflix.
the class TestQueueManager method setup.
@BeforeClass
public static void setup() throws Exception {
queue = mock(SQSObservableQueue.class);
when(queue.getOrCreateQueue()).thenReturn("junit_queue_url");
Answer<?> answer = new Answer<List<Message>>() {
@Override
public List<Message> answer(InvocationOnMock invocation) throws Throwable {
List<Message> copy = new LinkedList<>();
copy.addAll(messages);
messages.clear();
return copy;
}
};
when(queue.receiveMessages()).thenAnswer(answer);
when(queue.getOnSubscribe()).thenCallRealMethod();
when(queue.observe()).thenCallRealMethod();
when(queue.getName()).thenReturn(Status.COMPLETED.name());
Task task0 = new Task();
task0.setStatus(Status.IN_PROGRESS);
task0.setTaskId("t0");
task0.setReferenceTaskName("t0");
task0.setTaskType(Wait.NAME);
Workflow workflow0 = new Workflow();
workflow0.setWorkflowId("v_0");
workflow0.getTasks().add(task0);
Task task2 = new Task();
task2.setStatus(Status.IN_PROGRESS);
task2.setTaskId("t2");
task2.setTaskType(Wait.NAME);
Workflow workflow2 = new Workflow();
workflow2.setWorkflowId("v_2");
workflow2.getTasks().add(task2);
doAnswer(new Answer<Void>() {
@SuppressWarnings("unchecked")
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
List<Message> msgs = invocation.getArgument(0, List.class);
System.out.println("got messages to publish: " + msgs);
messages.addAll(msgs);
return null;
}
}).when(queue).publish(any());
es = mock(ExecutionService.class);
assertNotNull(es);
doReturn(workflow0).when(es).getExecutionStatus(eq("v_0"), anyBoolean());
doReturn(workflow2).when(es).getExecutionStatus(eq("v_2"), anyBoolean());
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
System.out.println("Updating task: " + invocation.getArgument(0, Task.class));
updatedTasks.add(invocation.getArgument(0, Task.class));
return null;
}
}).when(es).updateTask(any(Task.class));
}
Aggregations