Skip to content
Snippets Groups Projects
Commit 0293b76f authored by Damien MARCHAT's avatar Damien MARCHAT
Browse files

wip : setting up the base project

parent 4ddba7e7
No related branches found
No related tags found
No related merge requests found
Showing with 111 additions and 13 deletions
package io.takima.temporalpractice;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TemporalPracticeApplication {
private static final Logger log = LoggerFactory.getLogger(TemporalPracticeApplication.class);
public static void main(String[] args) {
log.info("Hello World!");
}
}
package io.takima.temporalpractice.bakery;
public class BakeService {
}
package io.takima.temporalpractice.bakery;
public class BatterService {
}
package io.takima.temporalpractice.bakery;
public class BestCookieWorkflow {
public void orderCookie() {
System.out.println("Cookie ordered... Yuum");
}
}
\ No newline at end of file
package io.takima.temporalpractice.bakery;
public class KitchenApp {
public static void main(String[] args) {}
}
package io.takima.temporalpractice.signals;
import io.takima.temporalpractice.signals.InventoryWorkflow.ConsumeSignal;
import io.temporal.activity.ActivityInterface;
@ActivityInterface
public interface InventoryActivity {
void reserve(ConsumeSignal input);
}
package io.takima.temporalpractice.signals;
import io.takima.temporalpractice.signals.InventoryWorkflow.ConsumeSignal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class InventoryActivityImpl implements InventoryActivity {
private static final Logger logger = LoggerFactory.getLogger(InventoryWorkflowImpl.class);
int counter;
public InventoryActivityImpl(int inventorySize){
this.counter = inventorySize;
}
@Override
public void reserve(ConsumeSignal input) {
int currentValue = counter;
try {
//Simulate async work
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
counter = currentValue - 1;
logger.info("counter: " + counter);
}
}
package io.takima.temporalpractice.signals;
import io.temporal.workflow.SignalMethod;
import io.temporal.workflow.WorkflowInterface;
import io.temporal.workflow.WorkflowMethod;
@WorkflowInterface
public interface InventoryWorkflow {
@WorkflowMethod
void run();
@SignalMethod
void reserve(ConsumeSignal input);
record ConsumeSignal(int amount) {
}
}
package io.takima.temporalpractice.signals;
import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowOptions;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import static io.takima.temporalpractice.temporal.TemporalUtils.*;
public class MSMain {
// Our inventory will contain 1000 elements and we will send 1000 signals, lets see how it goes
static int inventoryToDecrement = 1000;
public static void main(String[] args) {
var worker = FACTORY.newWorker(MASTERING_SIGNALS_QUEUE);
worker.registerActivitiesImplementations(new InventoryActivityImpl(inventoryToDecrement));
worker.registerWorkflowImplementationTypes(InventoryWorkflowImpl.class);
FACTORY.start();
var workflow = CLIENT.newWorkflowStub(
InventoryWorkflow.class,
WorkflowOptions.newBuilder().setTaskQueue(MASTERING_SIGNALS_QUEUE).setWorkflowId("inventory").build()
);
WorkflowClient.start(workflow::run);
try (ExecutorService executor = Executors.newVirtualThreadPerTaskExecutor()) {
// Submit 1000 tasks
for (int i = 1; i < inventoryToDecrement; i++) {
executor.submit(() -> {;
workflow.reserve(new InventoryWorkflow.ConsumeSignal(1));
});
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment