Search in sources :

Example 1 with CreateQueueRequest

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);
}
Also used : Task(com.google.cloud.tasks.v2.Task) CreateTaskRequest(com.google.cloud.tasks.v2.CreateTaskRequest) CreateQueueRequest(com.google.cloud.tasks.v2.CreateQueueRequest) Queue(com.google.cloud.tasks.v2.Queue) BeforeClass(org.junit.BeforeClass)

Example 2 with CreateQueueRequest

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");
    }
}
Also used : HttpRequest(com.google.cloud.tasks.v2.HttpRequest) Task(com.google.cloud.tasks.v2.Task) CreateQueueRequest(com.google.cloud.tasks.v2.CreateQueueRequest) CloudTasksClient(com.google.cloud.tasks.v2.CloudTasksClient) QueueName(com.google.cloud.tasks.v2.QueueName) Queue(com.google.cloud.tasks.v2.Queue) LocationName(com.google.cloud.tasks.v2.LocationName)

Example 3 with CreateQueueRequest

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");
    }
}
Also used : HttpRequest(com.google.cloud.tasks.v2.HttpRequest) Task(com.google.cloud.tasks.v2.Task) CreateQueueRequest(com.google.cloud.tasks.v2.CreateQueueRequest) CloudTasksClient(com.google.cloud.tasks.v2.CloudTasksClient) QueueName(com.google.cloud.tasks.v2.QueueName) Queue(com.google.cloud.tasks.v2.Queue) LocationName(com.google.cloud.tasks.v2.LocationName)

Aggregations

CreateQueueRequest (com.google.cloud.tasks.v2.CreateQueueRequest)3 Queue (com.google.cloud.tasks.v2.Queue)3 Task (com.google.cloud.tasks.v2.Task)3 CloudTasksClient (com.google.cloud.tasks.v2.CloudTasksClient)2 HttpRequest (com.google.cloud.tasks.v2.HttpRequest)2 LocationName (com.google.cloud.tasks.v2.LocationName)2 QueueName (com.google.cloud.tasks.v2.QueueName)2 CreateTaskRequest (com.google.cloud.tasks.v2.CreateTaskRequest)1 BeforeClass (org.junit.BeforeClass)1