use of com.google.cloud.tasks.v2.CreateQueueRequest in project java-tasks by googleapis.
the class ITSystemTest method setUp.
@BeforeClass
public static void setUp() throws IOException {
client = CloudTasksClient.create();
/* create queue */
Queue createQueue = Queue.newBuilder().setName(QUEUE_NAME).setState(Queue.State.RUNNING).build();
CreateQueueRequest queueRequest = CreateQueueRequest.newBuilder().setParent(LOCATION_NAME).setQueue(createQueue).build();
queue = client.createQueue(queueRequest);
/* create task */
Task createTask = Task.newBuilder().setName(TASK_NAME).setHttpRequest(HttpRequest.newBuilder().setBody(ByteString.copyFrom(PAYLOAD, Charset.defaultCharset())).setUrl(URL).setHttpMethod(HttpMethod.POST).build()).build();
CreateTaskRequest taskRequest = CreateTaskRequest.newBuilder().setParent(QUEUE_NAME).setTask(createTask).build();
task = client.createTask(taskRequest);
}
use of com.google.cloud.tasks.v2.CreateQueueRequest in project java-tasks by googleapis.
the class TasksSampleApplication method main.
/**
* Runs the Cloud Tasks sample application.
*/
public static void main(String[] args) throws IOException {
String projectId = ServiceOptions.getDefaultProjectId();
LocationName parent = LocationName.of(projectId, LOCATION_ID);
QueueName queueName = QueueName.of(parent.getProject(), parent.getLocation(), GRAALVM_TEST_QUEUE_NAME + UUID.randomUUID().toString());
try (CloudTasksClient client = CloudTasksClient.create()) {
// Create queue
Queue queue = Queue.newBuilder().setName(queueName.toString()).setRateLimits(RateLimits.newBuilder().setMaxConcurrentDispatches(1).build()).build();
CreateQueueRequest createQueueRequest = CreateQueueRequest.newBuilder().setParent(parent.toString()).setQueue(queue).build();
Queue createdQueue = client.createQueue(createQueueRequest);
System.out.println("Test queue ready: " + createdQueue);
// Create task
HttpRequest taskTarget = HttpRequest.newBuilder().setUrl("https://google.com").setHttpMethod(HttpMethod.GET).build();
Task taskRequest = Task.newBuilder().setHttpRequest(taskTarget).build();
Task task = client.createTask(queueName, taskRequest);
System.out.println("Created task: " + task);
// Cleanup
client.purgeQueue(queueName);
System.out.println("Queue purged");
client.deleteQueue(queueName);
System.out.println("Queue deleted");
}
}
use of com.google.cloud.tasks.v2.CreateQueueRequest in project native-image-support-java by GoogleCloudPlatform.
the class TasksSampleApplication method main.
/**
* Runs the Cloud Tasks sample application.
*/
public static void main(String[] args) throws IOException {
String projectId = ServiceOptions.getDefaultProjectId();
LocationName parent = LocationName.of(projectId, "us-east1");
QueueName queueName = QueueName.of(parent.getProject(), parent.getLocation(), GRAALVM_TEST_QUEUE_NAME + UUID.randomUUID().toString());
try (CloudTasksClient client = CloudTasksClient.create()) {
// Create queue
Queue queue = Queue.newBuilder().setName(queueName.toString()).setRateLimits(RateLimits.newBuilder().setMaxConcurrentDispatches(1).build()).build();
CreateQueueRequest createQueueRequest = CreateQueueRequest.newBuilder().setParent(parent.toString()).setQueue(queue).build();
Queue createdQueue = client.createQueue(createQueueRequest);
System.out.println("Test queue ready: " + createdQueue);
// Create task
HttpRequest taskTarget = HttpRequest.newBuilder().setUrl("https://google.com").setHttpMethod(HttpMethod.GET).build();
Task taskRequest = Task.newBuilder().setHttpRequest(taskTarget).build();
Task task = client.createTask(queueName, taskRequest);
System.out.println("Created task: " + task);
// Cleanup
client.purgeQueue(queueName);
System.out.println("Queue purged");
client.deleteQueue(queueName);
System.out.println("Queue deleted");
}
}
Aggregations