kandi background
Explore Kits

pubsub | EventBus system for publish and subscribe to events | Pub Sub library

 by   mycila Java Version: Current License: No License

 by   mycila Java Version: Current License: No License

Download this library from

kandi X-RAY | pubsub Summary

pubsub is a Java library typically used in Messaging, Pub Sub applications. pubsub has no bugs, it has no vulnerabilities, it has build file available and it has low support. You can download it from GitHub.
Mycila Event is a new powerful event framework for in-memory event management. It has a lot of features similar to EventBus but is better written and uses Java Concurrency features to provide you with:.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • pubsub has a low active ecosystem.
  • It has 30 star(s) with 6 fork(s). There are 3 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 1 open issues and 8 have been closed. On average issues are closed in 379 days. There are no pull requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of pubsub is current.
pubsub Support
Best in #Pub Sub
Average in #Pub Sub
pubsub Support
Best in #Pub Sub
Average in #Pub Sub

quality kandi Quality

  • pubsub has 0 bugs and 0 code smells.
pubsub Quality
Best in #Pub Sub
Average in #Pub Sub
pubsub Quality
Best in #Pub Sub
Average in #Pub Sub

securitySecurity

  • pubsub has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • pubsub code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
pubsub Security
Best in #Pub Sub
Average in #Pub Sub
pubsub Security
Best in #Pub Sub
Average in #Pub Sub

license License

  • pubsub does not have a standard license declared.
  • Check the repository for any license declaration and review the terms closely.
  • Without a license, all rights are reserved, and you cannot use the library in your applications.
pubsub License
Best in #Pub Sub
Average in #Pub Sub
pubsub License
Best in #Pub Sub
Average in #Pub Sub

buildReuse

  • pubsub releases are not available. You will need to build from source code and install.
  • Build file is available. You can build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
  • pubsub saves you 1505 person hours of effort in developing the same functionality from scratch.
  • It has 3354 lines of code, 338 functions and 52 files.
  • It has medium code complexity. Code complexity directly impacts maintainability of the code.
pubsub Reuse
Best in #Pub Sub
Average in #Pub Sub
pubsub Reuse
Best in #Pub Sub
Average in #Pub Sub
Top functions reviewed by kandi - BETA

kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here

Get all kandi verified functions for this library.

Get all kandi verified functions for this library.

pubsub Key Features

ErrorHandlers.ignoreErrors(): ignore all exceptions thrown by subscribers

ErrorHandlers.rethrow(): the default behavior.

Topics.only(exactName): matches a single topic name. Example: Topics.only("app/events/buttons/ok")

Topics.topics(pattern): matches several topic by using an Ant expression. Example: Topics.topics("app/events/buttons/**")

Topics.any(): matches any topic

Topics.not(matcher): invert the given matcher

matcher.and(matcher): any matcher can be composed with another matcher with an and. In this case, all matchers must match given topic event for the subscriber to receive it. This is quite an uncommon case.

matcher.or(matcher): any matcher can be composed with another matcher with an or. In this case, the subscriber will receive events matching the two matchers. This is a common case where you would like to receive in one subscriber the same events from different topics.

Listeners are called in the order they subscribed

Events are published one after one

Only one thread can publish at a time

Listeners are called in the order they subscribed

Events are published immediately

Several threads can publish at a time

Listeners are called in the order they subscribed

Events are published one after one

Many threads can enqueue an event at one time

One background thread is responsible to dequeue and fire events

A queue is used to enqueue events before they are processed.

Listeners are called in the order they subscribed

Several events (so listeners) are processed at the same time

Many threads can publish an event at one time

Several background threads are responsible for firing events

Listeners are called unordered

Events are published one after one

Many threads can enqueue an event at one time

A thread-pool is used to send each event to each subscriber

Listeners are called unordered

Several events are published at the same time

Many threads can enqueue an event at one time

A thread-pool is used to send each event to each subscriber

Executors.immediate(): execute the runnable immediately

Executors.blocking(): idem, but blocks so that only one thread can execute a subscriber at a time

Maven Repository

copy iconCopydownload iconDownload
<dependency>
    <groupId>com.mycila</groupId>
    <artifactId>mycila-pubsub</artifactId>
    <version>X.Y.ga</version>
</dependency>

Sample

copy iconCopydownload iconDownload
import static com.mycila.event.api.topic.Topics.*;

// first create an event service
Dispatcher dispatcher = Dispatchers.synchronousSafe(ErrorHandlers.rethrowErrorsAfterPublish());

// then subscribe
TopicMatcher matcher = only("app/events/swing/button").or(topics("app/events/swing/fields/**"));
dispatcher.subscribe(matcher, String.class, new Subscriber<String>() {
    public void onEvent(Event<String> event) throws Exception {
        System.out.println("Received: " + event.source());
    }
});

// and publish
dispatcher.publish(topic("app/events/swing/button"), "Hello !");

Usage

copy iconCopydownload iconDownload
dispatcher.subscribe(only("prog/events/a").or(matching("prog/events/b/**")), String.class, new Subscriber<String>() {
    public void onEvent(Event<String> event) throws Exception {
        sequence.add(event.getSource());
    }
});

Features

copy iconCopydownload iconDownload
dispatcher.subscribe(matcher, String.class, new Subscriber<String>() {
    public void onEvent(Event<String> event) throws Exception {
        System.out.println("Received: " + event.source());
    }
});

GCP API - Determining what role an resource instance has been created with

copy iconCopydownload iconDownload
            bool roleFound = false;
            bool userFound = false;
            bool exception = false;
            try
            {
                Policy policyResponse = Client.GetIamPolicy(Resource);
                var bindings = policyResponse.Bindings;
                foreach (var item in bindings)
                {
                    if (AcceptedRoles.Contains(item.Role))
                        roleFound = true;

                    foreach (var user in item.Members)
                    {
                        string testUser = user;
                        if (user.Substring(0, 5) == "user:")
                        {
                            testUser = user.Substring(5);
                        }
                        else if (user.Substring(0, 6) == "group:")
                        {
                            testUser = user.Substring(6);
                        }
                        if (Settings.UserTestList.Contains(testUser))
                            userFound = true;
                    }
                }
            }
            catch (Grpc.Core.RpcException)
            {
                exception = true;
            }

            Assert.True(roleFound);
            Assert.True(userFound);
            Assert.False(exception);

Intermittent authentication error when posting to a pubsub topic

copy iconCopydownload iconDownload
import json
from google.cloud import pubsub_v1
from google.auth import jwt

def post_messages(credentials_path, topic, list_of_messages):

    credentials_dict = json.load(open(credentials_path,'r'))

    audience = "https://pubsub.googleapis.com/google.pubsub.v1.Publisher"
    credentials_ob = jwt.Credentials.from_service_account_info(
        credentials_dict, audience=audience
    )

    publisher = pubsub_v1.PublisherClient(credentials=credentials_ob)

    for message_dict in list_of_message_dicts:
    
        message = json.dumps(message_dict, default=str).encode("utf-8")
    
        future = publisher.publish(topic, message)
google-api-core==2.4.0
google-api-python-client==2.36.0
google-auth==2.3.2
google-auth-httplib2==0.1.0
google-auth-oauthlib==0.4.6
google-cloud-core==2.1.0
google-cloud-pubsub==2.9.0
import json
from google.cloud import pubsub_v1
from google.auth import jwt

def post_messages(credentials_path, topic, list_of_messages):

    credentials_dict = json.load(open(credentials_path,'r'))

    audience = "https://pubsub.googleapis.com/google.pubsub.v1.Publisher"
    credentials_ob = jwt.Credentials.from_service_account_info(
        credentials_dict, audience=audience
    )

    publisher = pubsub_v1.PublisherClient(credentials=credentials_ob)

    for message_dict in list_of_message_dicts:
    
        message = json.dumps(message_dict, default=str).encode("utf-8")
    
        future = publisher.publish(topic, message)
google-api-core==2.4.0
google-api-python-client==2.36.0
google-auth==2.3.2
google-auth-httplib2==0.1.0
google-auth-oauthlib==0.4.6
google-cloud-core==2.1.0
google-cloud-pubsub==2.9.0

Apache Beam Cloud Dataflow Streaming Stuck Side Input

copy iconCopydownload iconDownload
mytopic = ""
sql = "SELECT station_id, CURRENT_TIMESTAMP() timestamp FROM `bigquery-public-data.austin_bikeshare.bikeshare_stations` LIMIT 10"

def to_bqrequest(e, sql):
    from apache_beam.io import ReadFromBigQueryRequest
    yield ReadFromBigQueryRequest(query=sql)
     

def merge(e, side):
    for i in side:
        yield f"Main {e.decode('utf-8')} Side {i}"

pubsub = p | "Read PubSub topic" >> ReadFromPubSub(topic=mytopic)

side_pcol = (p | PeriodicImpulse(fire_interval=300, apply_windowing=False)
               | "ApplyGlobalWindow" >> WindowInto(window.GlobalWindows(),
                                           trigger=trigger.Repeatedly(trigger.AfterProcessingTime(5)),
                                           accumulation_mode=trigger.AccumulationMode.DISCARDING)
               | "To BQ Request" >> ParDo(to_bqrequest, sql=sql)
               | ReadAllFromBigQuery()
            )

final = (pubsub | "Merge" >> ParDo(merge, side=beam.pvalue.AsList(side_pcol))
                | Map(logging.info)
        )                    
    
p.run()

Terraform - How to initialize set variable in tfvars

copy iconCopydownload iconDownload
roles = [
  "roles/cloudsql.client",
  "roles/bigquery.dataEditor",
  "roles/storage.admin",
  "roles/pubsub.edito",
  "roles/secretmanager.secretAccessor",
  "roles/artifactregistry.reader"
]

Google Scheduled functions: There was an error deploying functions?

copy iconCopydownload iconDownload
functions.pubsub.schedule("every 1 minute").onRun((context) => {}

Build a container image from inside a cloud function

copy iconCopydownload iconDownload
    build_client = cloudbuild_v1.CloudBuildClient()

    build = cloudbuild_v1.Build()

    build.steps = [{'name':'gcr.io/cloud-builders/docker',
                    'args':['build', '-t', 'us-central1-docker.pkg.dev/myproject/myrepo/imagename:latest','.']},
                    {'name':'gcr.io/cloud-builders/docker',
                    'args':['push', 'us-central1-docker.pkg.dev/myproject/myrepo/imagename:latest']}]  

    build_operation = build_client.create_build(project_id=myprojectid,build=build)

    build_result = build_operation.result()
tar -cvzf sourcecode.tar.gz .
gsutil cp sourcecode.tar.gz gs://myproject_cloudbuild
    build_client = cloudbuild_v1.CloudBuildClient()

    build = cloudbuild_v1.Build()
    
    build.source = {"storage_source":{"bucket":"myproject_cloudbuild", "object_":"gs://myproject_cloudbuild/sourcecode.tar.gz"}}

    build.steps = [{'name':'gcr.io/cloud-builders/docker',
                    'args':['build', '-t', 'us-central1-docker.pkg.dev/myproject/myrepo/imagename:latest','.']},
                    {'name':'gcr.io/cloud-builders/docker',
                    'args':['push', 'us-central1-docker.pkg.dev/myproject/myrepo/imagename:latest']}]  

    build_operation = build_client.create_build(project_id=myprojectid,build=build)

    build_result = build_operation.result()
    build_client = cloudbuild_v1.CloudBuildClient()

    build = cloudbuild_v1.Build()

    build.steps = [{'name':'gcr.io/cloud-builders/docker',
                    'args':['build', '-t', 'us-central1-docker.pkg.dev/myproject/myrepo/imagename:latest','.']},
                    {'name':'gcr.io/cloud-builders/docker',
                    'args':['push', 'us-central1-docker.pkg.dev/myproject/myrepo/imagename:latest']}]  

    build_operation = build_client.create_build(project_id=myprojectid,build=build)

    build_result = build_operation.result()
tar -cvzf sourcecode.tar.gz .
gsutil cp sourcecode.tar.gz gs://myproject_cloudbuild
    build_client = cloudbuild_v1.CloudBuildClient()

    build = cloudbuild_v1.Build()
    
    build.source = {"storage_source":{"bucket":"myproject_cloudbuild", "object_":"gs://myproject_cloudbuild/sourcecode.tar.gz"}}

    build.steps = [{'name':'gcr.io/cloud-builders/docker',
                    'args':['build', '-t', 'us-central1-docker.pkg.dev/myproject/myrepo/imagename:latest','.']},
                    {'name':'gcr.io/cloud-builders/docker',
                    'args':['push', 'us-central1-docker.pkg.dev/myproject/myrepo/imagename:latest']}]  

    build_operation = build_client.create_build(project_id=myprojectid,build=build)

    build_result = build_operation.result()
    build_client = cloudbuild_v1.CloudBuildClient()

    build = cloudbuild_v1.Build()

    build.steps = [{'name':'gcr.io/cloud-builders/docker',
                    'args':['build', '-t', 'us-central1-docker.pkg.dev/myproject/myrepo/imagename:latest','.']},
                    {'name':'gcr.io/cloud-builders/docker',
                    'args':['push', 'us-central1-docker.pkg.dev/myproject/myrepo/imagename:latest']}]  

    build_operation = build_client.create_build(project_id=myprojectid,build=build)

    build_result = build_operation.result()
tar -cvzf sourcecode.tar.gz .
gsutil cp sourcecode.tar.gz gs://myproject_cloudbuild
    build_client = cloudbuild_v1.CloudBuildClient()

    build = cloudbuild_v1.Build()
    
    build.source = {"storage_source":{"bucket":"myproject_cloudbuild", "object_":"gs://myproject_cloudbuild/sourcecode.tar.gz"}}

    build.steps = [{'name':'gcr.io/cloud-builders/docker',
                    'args':['build', '-t', 'us-central1-docker.pkg.dev/myproject/myrepo/imagename:latest','.']},
                    {'name':'gcr.io/cloud-builders/docker',
                    'args':['push', 'us-central1-docker.pkg.dev/myproject/myrepo/imagename:latest']}]  

    build_operation = build_client.create_build(project_id=myprojectid,build=build)

    build_result = build_operation.result()
    build_client = cloudbuild_v1.CloudBuildClient()

    build = cloudbuild_v1.Build()

    build.steps = [{'name':'gcr.io/cloud-builders/docker',
                    'args':['build', '-t', 'us-central1-docker.pkg.dev/myproject/myrepo/imagename:latest','.']},
                    {'name':'gcr.io/cloud-builders/docker',
                    'args':['push', 'us-central1-docker.pkg.dev/myproject/myrepo/imagename:latest']}]  

    build_operation = build_client.create_build(project_id=myprojectid,build=build)

    build_result = build_operation.result()
tar -cvzf sourcecode.tar.gz .
gsutil cp sourcecode.tar.gz gs://myproject_cloudbuild
    build_client = cloudbuild_v1.CloudBuildClient()

    build = cloudbuild_v1.Build()
    
    build.source = {"storage_source":{"bucket":"myproject_cloudbuild", "object_":"gs://myproject_cloudbuild/sourcecode.tar.gz"}}

    build.steps = [{'name':'gcr.io/cloud-builders/docker',
                    'args':['build', '-t', 'us-central1-docker.pkg.dev/myproject/myrepo/imagename:latest','.']},
                    {'name':'gcr.io/cloud-builders/docker',
                    'args':['push', 'us-central1-docker.pkg.dev/myproject/myrepo/imagename:latest']}]  

    build_operation = build_client.create_build(project_id=myprojectid,build=build)

    build_result = build_operation.result()

How to stop and start a PubSub programatically through the MessageReceiver in Java

copy iconCopydownload iconDownload
private Subscriber StartSubscriber() {

    Subscriber subscriber = null;
    try {
        subscriber = Subscriber.newBuilder(subscriptionName, receiver).build();
        subscriber.startAsync().awaitRunning();
        System.out.printf("Listening for messages on %s:\n", subscriptionName.toString());
        subscriber.awaitTerminated(30, TimeUnit.SECONDS);
        return subscriber;
    } catch (TimeoutException timeoutException) {
        // Shut down the subscriber after 30s. Stop receiving messages.
        System.out.printf("Error \n");
        subscriber.stopAsync();
    }

}

private void StopSubscriber(Subscriber subscriber) {

    System.out.printf("Stoping subscriber\n");
    subscriber.stopAsync();
}


public void test() {
    Subscriber subscriber = StartSubscriber();
    StopSubscriber(subscriber);
}

creating dataproc cluster with multiple jars

copy iconCopydownload iconDownload
--properties=^#^spark:spark.jars.packages=artifact1,artifact2,artifact3#spark:spark.driver.memory=3000m

Finding messageID of Pub/Sub message triggering Cloud Function

copy iconCopydownload iconDownload
import  "cloud.google.com/go/functions/metadata"

func YourFunc(ctx context.Context, m PubSubMessage) error {
    metadata, err := metadata.FromContext(ctx)
    if err != nil {
        // Handle Error
    }
    messageId := metadata.EventID

    // Rest of your code below here.
}

Cloud function on GCP: no exit log

copy iconCopydownload iconDownload
vote_stage oga5hymuzx4p Function execution took 66563 ms, 
finished with status: 'ok'

Community Discussions

Trending Discussions on pubsub
  • GCP API - Determining what role an resource instance has been created with
  • Google Firebase Functions deployment fails - what can I do?
  • Intermittent authentication error when posting to a pubsub topic
  • Failed to unregister class Chrome_WidgetWin_0. Error
  • Apache Beam Cloud Dataflow Streaming Stuck Side Input
  • Terraform - How to initialize set variable in tfvars
  • Google Scheduled functions: There was an error deploying functions?
  • Build a container image from inside a cloud function
  • How to stop and start a PubSub programatically through the MessageReceiver in Java
  • creating dataproc cluster with multiple jars
Trending Discussions on pubsub

QUESTION

GCP API - Determining what role an resource instance has been created with

Asked 2022-Mar-17 at 16:54

For the project I'm on, I am tasked with creating a testing app that uses Terraform to create a resource instance and then test that it was created properly. The purpose is testing the Terraform Script result by validating certain characteristics of the resource created. That's the broad outline.

For several of these scripts a resource is assigned a role. It could be a PubSub subscription, DataCatalog, etc.

Example Terraform code for a Spanner Database assigning roles/spanner.databaseAdmin:

resource "google_spanner_database_iam_member" "user_database_admin" {
  for_each = toset(var.iam_user_database_admins)
  project = var.project
  instance = var.instance_id
  database = google_spanner_database.spanner_database.name
  role       = "roles/spanner.databaseAdmin"
  member     =  "user:${each.key}"
}

So my question is this: Is there a way using a .NET GCP API to make a call to determine that the role was assigned? I can test for permissions via a TestIamPermissions method off of the client object and that's what I'm currently doing. But that gives me a sometimes long list of possible permissions. Is there a way to say "does this spanner database have the roles/spanner.databaseAdmin assigned?"

Here's an example of code testing for permissions on a PubSub Subscription:

TestIamPermissionsRequest subscriptionRequest = new TestIamPermissionsRequest
{
    ResourceAsResourceName = SubscriptionName.FromProjectSubscription(projectId, subscriptionId),
    Permissions = {
        "pubsub.subscriptions.get",
        "pubsub.subscriptions.delete",
        "pubsub.subscriptions.update"
    }
};
TestIamPermissionsResponse subscriptionResponse = publisher.TestIamPermissions(subscriptionRequest);

Seems like there ought to be a cleaner way to do this, but being somewhat new to GCP, I haven't found a way yet. Suggestions will be welcome.

ANSWER

Answered 2022-Mar-17 at 16:54

Thought I should close this question off with what I eventually discovered. The proper question isn't what role is assigned an instance of a resource, but what users have been allowed to use the resource and with what role.

The proper call is GetIamPolicy which is available in the APIs for all of the resources that I've been working with. The problem was that I wasn't seeing anything due to no user accounts being assigned to the resource. I updated the Terraform script to assign a user to the resource with the required roles. When calling GetIamPolicy, it returns an array in the Bindings that lists roles and users that are assigned. This was the information I needed. Going down the path of using TestIamPermissions was unneeded.

Here's an example my use of this:

            bool roleFound = false;
            bool userFound = false;
            bool exception = false;
            try
            {
                Policy policyResponse = Client.GetIamPolicy(Resource);
                var bindings = policyResponse.Bindings;
                foreach (var item in bindings)
                {
                    if (AcceptedRoles.Contains(item.Role))
                        roleFound = true;

                    foreach (var user in item.Members)
                    {
                        string testUser = user;
                        if (user.Substring(0, 5) == "user:")
                        {
                            testUser = user.Substring(5);
                        }
                        else if (user.Substring(0, 6) == "group:")
                        {
                            testUser = user.Substring(6);
                        }
                        if (Settings.UserTestList.Contains(testUser))
                            userFound = true;
                    }
                }
            }
            catch (Grpc.Core.RpcException)
            {
                exception = true;
            }

            Assert.True(roleFound);
            Assert.True(userFound);
            Assert.False(exception);

Source https://stackoverflow.com/questions/71442133

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install pubsub

You can download it from GitHub.
You can use pubsub like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the pubsub component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

Support

Mycila Event is a new powerful event framework for in-memory event management. It has a lot of features similar to EventBus but is better designed, uses Java Concurrency features and has a lot of more event features than EventBus, which are really useful when you work with a complex system driven by event messaging.

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases
Explore Kits

Save this library and start creating your kit

Explore Related Topics

Share this Page

share link
Consider Popular Pub Sub Libraries
Try Top Libraries by mycila
Compare Pub Sub Libraries with Highest Support
Compare Pub Sub Libraries with Highest Quality
Compare Pub Sub Libraries with Highest Security
Compare Pub Sub Libraries with Permissive License
Compare Pub Sub Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases
Explore Kits

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.