├── .asf.yaml ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── bot.yml │ ├── ci.yml │ └── codeql.yml ├── .gitignore ├── .golangci.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── Dockerfile ├── LICENSE ├── Makefile ├── NOTICE ├── README.md ├── distribution ├── LICENSE.bin.txt └── license │ ├── LICENSE-athenz.txt │ ├── LICENSE-cobra.txt │ ├── LICENSE-compress.txt │ ├── LICENSE-errors.txt │ ├── LICENSE-go-avro.txt │ ├── LICENSE-go-cmp.txt │ ├── LICENSE-go-spew.txt │ ├── LICENSE-logrus.txt │ ├── LICENSE-lz4.txt │ ├── LICENSE-mousetrap.txt │ ├── LICENSE-murmur3.txt │ ├── LICENSE-oauth2.txt │ ├── LICENSE-opentracing.txt │ ├── LICENSE-perks.txt │ ├── LICENSE-pflag.txt │ ├── LICENSE-pretty.txt │ ├── LICENSE-prometheus.txt │ ├── LICENSE-protobuf.txt │ ├── LICENSE-testify.txt │ ├── LICENSE-uuid.txt │ └── LICENSE-zstd.txt ├── docs └── release-process.md ├── examples ├── consumer-listener │ └── consumer-listener.go ├── consumer │ └── consumer.go ├── producer │ └── producer.go └── reader │ └── reader.go ├── go.mod ├── go.sum ├── integration-tests ├── blue-green │ └── docker-compose.yml ├── certs │ ├── broker-cert.pem │ ├── broker-key.pem │ ├── cacert.pem │ ├── client-cert.pem │ ├── client-key.pem │ ├── generate.sh │ └── openssl.cnf ├── clustered │ └── docker-compose.yml ├── conf │ ├── .htpasswd │ ├── client.conf │ └── standalone.conf ├── extensible-load-manager │ └── docker-compose.yml ├── pb │ ├── build.sh │ ├── hello.pb.go │ ├── hello.proto │ ├── hi.pb.go │ └── hi.proto └── tokens │ ├── admin-token │ ├── secret.key │ └── token.txt ├── licenserc.toml ├── oauth2 ├── auth.go ├── auth_suite_test.go ├── authorization_tokenretriever.go ├── authorization_tokenretriever_test.go ├── cache │ └── cache.go ├── client_credentials_flow.go ├── client_credentials_flow_test.go ├── client_credentials_provider.go ├── client_credentials_provider_test.go ├── clock │ ├── clock.go │ └── testing │ │ └── fake_clock.go ├── config_tokenprovider.go ├── config_tokenprovider_test.go ├── data_url.go ├── data_url_test.go ├── device_code_flow.go ├── device_code_flow_test.go ├── device_code_provider.go ├── oidc_endpoint_provider.go ├── oidc_endpoint_provider_test.go └── store │ ├── keyring.go │ ├── memory.go │ └── store.go ├── perf ├── perf-consumer.go ├── perf-producer.go └── pulsar-perf-go.go ├── pulsar ├── ack_grouping_tracker.go ├── ack_grouping_tracker_test.go ├── auth │ ├── athenz.go │ ├── athenz_test.go │ ├── basic.go │ ├── basic_test.go │ ├── disabled.go │ ├── oauth2.go │ ├── oauth2_test.go │ ├── provider.go │ ├── tls.go │ └── token.go ├── backoff │ ├── backoff.go │ └── backoff_test.go ├── batcher_builder.go ├── blue_green_migration_test.go ├── client.go ├── client_impl.go ├── client_impl_clustered_test.go ├── client_impl_test.go ├── client_impl_with_slog_test.go ├── consumer.go ├── consumer_impl.go ├── consumer_interceptor.go ├── consumer_multitopic.go ├── consumer_multitopic_test.go ├── consumer_partition.go ├── consumer_partition_test.go ├── consumer_regex.go ├── consumer_regex_test.go ├── consumer_test.go ├── consumer_zero_queue.go ├── consumer_zero_queue_test.go ├── crypto │ ├── crypto_failure_action.go │ ├── crypto_key_reader.go │ ├── default_crypto_Key_reader.go │ ├── default_crypto_key_reader_test.go │ ├── default_message_crypto.go │ ├── default_message_crypto_test.go │ ├── encryption_key_Info.go │ ├── message_crypto.go │ ├── message_metadata.go │ ├── message_metadata_test.go │ └── testdata │ │ ├── pri_key_rsa.pem │ │ ├── pub_key_rsa.pem │ │ ├── truncated_pub_key_rsa.pem │ │ ├── wrong_encode_pub_key_rsa.pem │ │ └── wrong_encoded_pri_key_rsa.pem ├── default_router.go ├── default_router_bench_test.go ├── default_router_test.go ├── dlq_router.go ├── encryption.go ├── error.go ├── error_test.go ├── extensible_load_manager_test.go ├── helper.go ├── helper_for_test.go ├── helper_test.go ├── impl_message.go ├── impl_message_test.go ├── internal │ ├── batch_builder.go │ ├── blocking_queue.go │ ├── blocking_queue_test.go │ ├── buffer.go │ ├── buffer_test.go │ ├── channel_cond.go │ ├── channel_cond_test.go │ ├── checksum.go │ ├── checksum_test.go │ ├── client_handlers.go │ ├── client_handlers_test.go │ ├── closable.go │ ├── commands.go │ ├── commands_test.go │ ├── compression │ │ ├── compression.go │ │ ├── compression_bench_test.go │ │ ├── compression_test.go │ │ ├── lz4.go │ │ ├── noop.go │ │ ├── test_data_sample.txt │ │ ├── zlib.go │ │ ├── zstd.go │ │ ├── zstd_cgo.go │ │ └── zstd_go.go │ ├── connection.go │ ├── connection_pool.go │ ├── connection_reader.go │ ├── crypto │ │ ├── consumer_decryptor.go │ │ ├── decryptor.go │ │ ├── encryptor.go │ │ ├── noop_decryptor.go │ │ ├── noop_encryptor.go │ │ └── producer_encryptor.go │ ├── hash.go │ ├── hash_test.go │ ├── helper.go │ ├── http_client.go │ ├── key_based_batch_builder.go │ ├── key_based_batch_builder_test.go │ ├── lookup_service.go │ ├── lookup_service_test.go │ ├── memory_limit_controller.go │ ├── memory_limit_controller_test.go │ ├── metrics.go │ ├── namespace_name.go │ ├── namespace_name_test.go │ ├── pulsar_proto │ │ ├── PulsarApi.pb.go │ │ ├── PulsarApi.proto │ │ └── README.md │ ├── pulsartracing │ │ ├── consumer_interceptor.go │ │ ├── consumer_interceptor_test.go │ │ ├── message_carrier_adaptors.go │ │ ├── message_carrier_util.go │ │ ├── message_carrier_util_test.go │ │ ├── producer_interceptor.go │ │ ├── producer_interceptor_test.go │ │ ├── readme.md │ │ └── span-enrichment.go │ ├── retry.go │ ├── retry_test.go │ ├── rpc_client.go │ ├── semaphore.go │ ├── semaphore_test.go │ ├── service_name_resolver.go │ ├── service_name_resolver_test.go │ ├── service_uri.go │ ├── service_uri_test.go │ ├── topic_name.go │ ├── topic_name_test.go │ ├── utils.go │ ├── utils_test.go │ ├── version.go │ └── version_test.go ├── key_shared_policy.go ├── key_shared_policy_test.go ├── log │ ├── log.go │ ├── logger.go │ ├── wrapper_logrus.go │ ├── wrapper_slog.go │ └── wrapper_slog_test.go ├── message.go ├── message_chunking_test.go ├── message_test.go ├── negative_acks_tracker.go ├── negative_acks_tracker_test.go ├── negative_backoff_policy.go ├── negative_backoff_policy_test.go ├── primitiveSerDe.go ├── primitiveSerDe_test.go ├── producer.go ├── producer_impl.go ├── producer_interceptor.go ├── producer_partition.go ├── producer_test.go ├── reader.go ├── reader_clustered_test.go ├── reader_impl.go ├── reader_test.go ├── retry_router.go ├── schema.go ├── schema_def_test.go ├── schema_test.go ├── single_partition_router.go ├── single_partition_router_test.go ├── table_view.go ├── table_view_impl.go ├── table_view_test.go ├── transaction.go ├── transaction_coordinator_client.go ├── transaction_disabled_test.go ├── transaction_impl.go └── transaction_test.go ├── pulsaradmin ├── CONTRIBUTING.md ├── README.md ├── alias.go └── pkg │ ├── admin │ ├── admin.go │ ├── admin_test.go │ ├── auth │ │ ├── oauth2.go │ │ ├── oauth2_test.go │ │ ├── provider.go │ │ ├── tls.go │ │ ├── token.go │ │ └── transport.go │ ├── broker_stats.go │ ├── brokers.go │ ├── brokers_test.go │ ├── cluster.go │ ├── config │ │ ├── api_version.go │ │ ├── api_version_test.go │ │ └── config.go │ ├── functions.go │ ├── functions_worker.go │ ├── namespace.go │ ├── namespace_test.go │ ├── ns_isolation_policy.go │ ├── packages.go │ ├── resource_quotas.go │ ├── schema.go │ ├── schema_test.go │ ├── sinks.go │ ├── sources.go │ ├── subscription.go │ ├── subscription_test.go │ ├── tenant.go │ ├── topic.go │ └── topic_test.go │ ├── rest │ ├── client.go │ ├── client_test.go │ └── errors.go │ └── utils │ ├── allocator_stats.go │ ├── auth_action.go │ ├── auth_polices.go │ ├── auth_polices_test.go │ ├── backlog_quota.go │ ├── batch_source_config.go │ ├── broker_ns_isolation_data.go │ ├── bundles_data.go │ ├── connector_definition.go │ ├── consumer_config.go │ ├── crypto_config.go │ ├── data.go │ ├── dispatch_rate.go │ ├── function_confg.go │ ├── function_state.go │ ├── function_status.go │ ├── functions_stats.go │ ├── home_dir.go │ ├── inactive_topic_policies.go │ ├── internal_configuration_data.go │ ├── load_manage_report.go │ ├── long_running_process_status.go │ ├── message.go │ ├── message_id.go │ ├── message_id_test.go │ ├── metrics.go │ ├── namespace_name.go │ ├── namespace_name_test.go │ ├── ns_isolation_data.go │ ├── ns_ownership_status.go │ ├── package_metadata.go │ ├── package_name.go │ ├── package_name_test.go │ ├── package_type.go │ ├── persistence_policies.go │ ├── policies.go │ ├── producer_config.go │ ├── publish_rate.go │ ├── resource_quota.go │ ├── resources.go │ ├── retention_policies.go │ ├── schema_strategy.go │ ├── schema_util.go │ ├── sink_config.go │ ├── sink_status.go │ ├── source_config.go │ ├── source_status.go │ ├── subscription_auth_mode.go │ ├── topic_auto_creation_config.go │ ├── topic_domain.go │ ├── topic_name.go │ ├── topic_name_test.go │ ├── topic_type.go │ ├── topics_stats_stream.go │ ├── update_options.go │ ├── utils.go │ ├── utils_test.go │ ├── window_confing.go │ └── worker_info.go └── scripts ├── pulsar-test-service-start.sh ├── pulsar-test-service-stop.sh ├── run-ci-blue-green-cluster.sh ├── run-ci-clustered.sh ├── run-ci-extensible-load-manager.sh ├── run-ci.sh └── stage-release.sh /.asf.yaml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | github: 19 | description: "Apache Pulsar Go Client Library" 20 | homepage: https://pulsar.apache.org/ 21 | labels: 22 | - pulsar 23 | - pubsub 24 | - messaging 25 | - streaming 26 | - queuing 27 | - event-streaming 28 | - golang 29 | - go 30 | features: 31 | # Enable wiki for documentation 32 | wiki: true 33 | # Enable issues management 34 | issues: true 35 | # Enable projects for project management boards 36 | projects: true 37 | enabled_merge_buttons: 38 | # enable squash button: 39 | squash: true 40 | # disable merge button: 41 | merge: false 42 | # disable rebase button: 43 | rebase: false 44 | 45 | protected_branches: 46 | master: 47 | required_pull_request_reviews: 48 | require_code_owner_reviews: true 49 | required_approving_review_count: 1 50 | 51 | # Requires all conversations on code to be resolved before a pull request can be merged. 52 | required_conversation_resolution: true 53 | 54 | notifications: 55 | commits: commits@pulsar.apache.org 56 | issues: commits@pulsar.apache.org 57 | pullrequests: commits@pulsar.apache.org 58 | discussions: dev@pulsar.apache.org 59 | jira_options: link label 60 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | #### Expected behavior 8 | 9 | Tell us what should happen 10 | 11 | #### Actual behavior 12 | 13 | Tell us what happens instead 14 | 15 | #### Steps to reproduce 16 | 17 | How can we reproduce the issue 18 | 19 | #### System configuration 20 | **Pulsar version**: x.y 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Describe alternatives you've considered** 14 | A clear and concise description of any alternative solutions or features you've considered. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. 18 | -------------------------------------------------------------------------------- /.github/workflows/bot.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | name: Pulsar Bot 19 | on: 20 | issue_comment: 21 | types: [created] 22 | 23 | jobs: 24 | pulsarbot: 25 | runs-on: ubuntu-latest 26 | timeout-minutes: 10 27 | if: github.event_name == 'issue_comment' && contains(github.event.comment.body, '/pulsarbot') 28 | steps: 29 | - name: Execute pulsarbot command 30 | id: pulsarbot 31 | env: 32 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 33 | BOT_TARGET_REPOSITORY: apache/pulsar-client-go 34 | uses: apache/pulsar-test-infra/pulsarbot@master 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IDE generated files 2 | .idea/ 3 | 4 | # Mac swap file 5 | *.DS_Store 6 | 7 | # Linux swap file 8 | *.swp 9 | 10 | # Output of the go coverage tool 11 | *.out 12 | coverage.html 13 | 14 | perf/perf 15 | pulsar-perf 16 | bin 17 | 18 | vendor/ 19 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | # Run `make lint` from the root path of this project to check code with golangci-lint. 19 | 20 | run: 21 | timeout: 5m 22 | 23 | linters: 24 | # Uncomment this line to run only the explicitly enabled linters 25 | # disable-all: true 26 | 27 | # Run these linters in addition to the default ones 28 | enable: 29 | - bodyclose 30 | - goimports 31 | - lll 32 | - misspell 33 | - prealloc 34 | - revive 35 | - stylecheck 36 | - unconvert 37 | - unparam 38 | 39 | # Disable these default linters 40 | disable: 41 | - errcheck 42 | - staticcheck 43 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | # Explicit version of Pulsar and Golang images should be 19 | # set via the Makefile or CLI 20 | ARG PULSAR_IMAGE=apachepulsar/pulsar:latest 21 | 22 | ARG GO_VERSION=1.23 23 | FROM golang:$GO_VERSION as golang 24 | 25 | FROM $PULSAR_IMAGE 26 | USER root 27 | 28 | COPY --from=golang /usr/local/go /pulsar/go 29 | 30 | ENV PATH /pulsar/go/bin:$PATH 31 | 32 | RUN apk add git gcc musl-dev 33 | 34 | ### Add pulsar config 35 | COPY integration-tests/certs /pulsar/certs 36 | COPY integration-tests/tokens /pulsar/tokens 37 | COPY integration-tests/conf/.htpasswd \ 38 | integration-tests/conf/client.conf \ 39 | integration-tests/conf/standalone.conf \ 40 | /pulsar/conf/ 41 | 42 | COPY . /pulsar/pulsar-client-go 43 | 44 | ENV PULSAR_EXTRA_OPTS="-Dpulsar.auth.basic.conf=/pulsar/conf/.htpasswd" 45 | 46 | WORKDIR /pulsar/pulsar-client-go 47 | 48 | ENV GOPATH=/pulsar/go 49 | ENV GOCACHE=/tmp/go-cache 50 | 51 | ARG PULSAR_IMAGE 52 | ENV PULSAR_IMAGE=$PULSAR_IMAGE 53 | 54 | # Install dependencies 55 | RUN go mod download 56 | 57 | # Basic compilation 58 | RUN go build ./pulsar 59 | RUN go build ./pulsaradmin 60 | RUN go build -o bin/pulsar-perf ./perf 61 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | 2 | Apache Pulsar 3 | Copyright 2017-2019 The Apache Software Foundation 4 | 5 | This product includes software developed at 6 | The Apache Software Foundation (http://www.apache.org/). -------------------------------------------------------------------------------- /distribution/license/LICENSE-compress.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 The Go Authors. All rights reserved. 2 | Copyright (c) 2019 Klaus Post. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /distribution/license/LICENSE-errors.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Dave Cheney 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /distribution/license/LICENSE-go-cmp.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /distribution/license/LICENSE-go-spew.txt: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2012-2016 Dave Collins 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -------------------------------------------------------------------------------- /distribution/license/LICENSE-logrus.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Simon Eskildsen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /distribution/license/LICENSE-lz4.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Pierre Curto 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of xxHash nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /distribution/license/LICENSE-mousetrap.txt: -------------------------------------------------------------------------------- 1 | Copyright 2014 Alan Shreve 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /distribution/license/LICENSE-murmur3.txt: -------------------------------------------------------------------------------- 1 | Copyright 2013, Sébastien Paolacci. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the library nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /distribution/license/LICENSE-oauth2.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /distribution/license/LICENSE-perks.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) 2013 Blake Mizerany 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /distribution/license/LICENSE-pflag.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Alex Ogier. All rights reserved. 2 | Copyright (c) 2012 The Go Authors. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /distribution/license/LICENSE-pretty.txt: -------------------------------------------------------------------------------- 1 | Copyright 2012 Keith Rarick 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /distribution/license/LICENSE-protobuf.txt: -------------------------------------------------------------------------------- 1 | Copyright 2010 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | -------------------------------------------------------------------------------- /distribution/license/LICENSE-testify.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2012-2018 Mat Ryer and Tyler Bunnell 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /distribution/license/LICENSE-uuid.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009,2014 Google Inc. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /distribution/license/LICENSE-zstd.txt: -------------------------------------------------------------------------------- 1 | Simplified BSD License 2 | 3 | Copyright (c) 2016, Datadog 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, 10 | this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | * Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software 16 | without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /examples/consumer-listener/consumer-listener.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package main 19 | 20 | import ( 21 | "fmt" 22 | "log" 23 | 24 | "github.com/apache/pulsar-client-go/pulsar" 25 | ) 26 | 27 | func main() { 28 | client, err := pulsar.NewClient(pulsar.ClientOptions{URL: "pulsar://localhost:6650"}) 29 | if err != nil { 30 | log.Fatal(err) 31 | } 32 | 33 | defer client.Close() 34 | 35 | channel := make(chan pulsar.ConsumerMessage, 100) 36 | 37 | options := pulsar.ConsumerOptions{ 38 | Topic: "topic-1", 39 | SubscriptionName: "my-subscription", 40 | Type: pulsar.Shared, 41 | } 42 | 43 | options.MessageChannel = channel 44 | 45 | consumer, err := client.Subscribe(options) 46 | if err != nil { 47 | log.Fatal(err) 48 | } 49 | 50 | defer consumer.Close() 51 | 52 | // Receive messages from channel. The channel returns a struct which contains message and the consumer from where 53 | // the message was received. It's not necessary here since we have 1 single consumer, but the channel could be 54 | // shared across multiple consumers as well 55 | for cm := range channel { 56 | msg := cm.Message 57 | fmt.Printf("Received message msgId: %v -- content: '%s'\n", 58 | msg.ID(), string(msg.Payload())) 59 | 60 | consumer.Ack(msg) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /examples/consumer/consumer.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package main 19 | 20 | import ( 21 | "context" 22 | "fmt" 23 | "log" 24 | 25 | "github.com/apache/pulsar-client-go/pulsar" 26 | ) 27 | 28 | func main() { 29 | client, err := pulsar.NewClient(pulsar.ClientOptions{URL: "pulsar://localhost:6650"}) 30 | if err != nil { 31 | log.Fatal(err) 32 | } 33 | 34 | defer client.Close() 35 | 36 | consumer, err := client.Subscribe(pulsar.ConsumerOptions{ 37 | Topic: "topic-1", 38 | SubscriptionName: "my-sub", 39 | Type: pulsar.Shared, 40 | }) 41 | if err != nil { 42 | log.Fatal(err) 43 | } 44 | defer consumer.Close() 45 | 46 | for i := 0; i < 10; i++ { 47 | msg, err := consumer.Receive(context.Background()) 48 | if err != nil { 49 | log.Fatal(err) 50 | } 51 | 52 | fmt.Printf("Received message msgId: %#v -- content: '%s'\n", 53 | msg.ID(), string(msg.Payload())) 54 | 55 | consumer.Ack(msg) 56 | } 57 | 58 | if err := consumer.Unsubscribe(); err != nil { 59 | log.Fatal(err) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /examples/producer/producer.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package main 19 | 20 | import ( 21 | "context" 22 | "fmt" 23 | "log" 24 | 25 | "github.com/apache/pulsar-client-go/pulsar" 26 | ) 27 | 28 | func main() { 29 | client, err := pulsar.NewClient(pulsar.ClientOptions{ 30 | URL: "pulsar://localhost:6650", 31 | }) 32 | 33 | if err != nil { 34 | log.Fatal(err) 35 | } 36 | 37 | defer client.Close() 38 | 39 | producer, err := client.CreateProducer(pulsar.ProducerOptions{ 40 | Topic: "topic-1", 41 | }) 42 | if err != nil { 43 | log.Fatal(err) 44 | } 45 | 46 | defer producer.Close() 47 | 48 | ctx := context.Background() 49 | 50 | for i := 0; i < 10; i++ { 51 | if msgId, err := producer.Send(ctx, &pulsar.ProducerMessage{ 52 | Payload: []byte(fmt.Sprintf("hello-%d", i)), 53 | }); err != nil { 54 | log.Fatal(err) 55 | } else { 56 | log.Println("Published message: ", msgId) 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /examples/reader/reader.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package main 19 | 20 | import ( 21 | "context" 22 | "fmt" 23 | "log" 24 | 25 | "github.com/apache/pulsar-client-go/pulsar" 26 | ) 27 | 28 | func main() { 29 | client, err := pulsar.NewClient(pulsar.ClientOptions{URL: "pulsar://localhost:6650"}) 30 | if err != nil { 31 | log.Fatal(err) 32 | } 33 | 34 | defer client.Close() 35 | 36 | reader, err := client.CreateReader(pulsar.ReaderOptions{ 37 | Topic: "topic-1", 38 | StartMessageID: pulsar.EarliestMessageID(), 39 | }) 40 | if err != nil { 41 | log.Fatal(err) 42 | } 43 | defer reader.Close() 44 | 45 | for reader.HasNext() { 46 | msg, err := reader.Next(context.Background()) 47 | if err != nil { 48 | log.Fatal(err) 49 | } 50 | 51 | fmt.Printf("Received message msgId: %#v -- content: '%s'\n", 52 | msg.ID(), string(msg.Payload())) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /integration-tests/certs/broker-cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIGHzCCBAegAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwgZIxCzAJBgNVBAYTAlVT 3 | MRMwEQYDVQQIDApDYWxpZm9ybmlhMSMwIQYDVQQKDBpBcGFjaGUgU29mdHdhcmUg 4 | Rm91bmRhdGlvbjEPMA0GA1UECwwGUHVsc2FyMRIwEAYDVQQDDAlQdWxzYXIgQ0Ex 5 | JDAiBgkqhkiG9w0BCQEWFWRldkBwdWxzYXIuYXBhY2hlLm9yZzAeFw0yMTA2MjIw 6 | NTU1MzlaFw0zMTA2MjAwNTU1MzlaMIGSMQswCQYDVQQGEwJVUzETMBEGA1UECAwK 7 | Q2FsaWZvcm5pYTEjMCEGA1UECgwaQXBhY2hlIFNvZnR3YXJlIEZvdW5kYXRpb24x 8 | DzANBgNVBAsMBlB1bHNhcjESMBAGA1UEAwwJbG9jYWxob3N0MSQwIgYJKoZIhvcN 9 | AQkBFhVkZXZAcHVsc2FyLmFwYWNoZS5vcmcwggEiMA0GCSqGSIb3DQEBAQUAA4IB 10 | DwAwggEKAoIBAQCqtRND1GELHgVfRSNBcvIeZ6o3ARieCKi7UGS13c8GAYJjpHId 11 | 9FEOT6K2HhqsdsgAgmNK8LcY5NWMyNascwZN3oW+ftTiXTB5EhOgdOaOnREiVbvQ 12 | cm6RIrQJQGp+Lbv3i3KUZzQ9ziTNu0OturKD2HADfZMMBCySTSZocws+tY3KykGr 13 | MeXsKuF+5WKlxBCJM4qWrC3izhzNLGsocwIkiqTXIaW79Tp0GpAB58j3QgR5rBCI 14 | cbDDtnAoLOuyQTkHakiCKT+kx6DpSbtptgNseeAuZAm8AGIrifSEEiOSPrvLNsem 15 | dkyORK+lupyp4mulXRyyGp8WofnH5qCGsrB/AgMBAAGjggF7MIIBdzAJBgNVHRME 16 | AjAAMBEGCWCGSAGG+EIBAQQEAwIGQDAzBglghkgBhvhCAQ0EJhYkT3BlblNTTCBH 17 | ZW5lcmF0ZWQgU2VydmVyIENlcnRpZmljYXRlMB0GA1UdDgQWBBR14LSJhdIK8UBr 18 | DWvSbfL2PmUK4DCBxwYDVR0jBIG/MIG8gBScEpVAELMJboc1hfTtqTV5sr3OCKGB 19 | mKSBlTCBkjELMAkGA1UEBhMCVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExIzAhBgNV 20 | BAoMGkFwYWNoZSBTb2Z0d2FyZSBGb3VuZGF0aW9uMQ8wDQYDVQQLDAZQdWxzYXIx 21 | EjAQBgNVBAMMCVB1bHNhciBDQTEkMCIGCSqGSIb3DQEJARYVZGV2QHB1bHNhci5h 22 | cGFjaGUub3JnggkAmcALIaQWyzkwDgYDVR0PAQH/BAQDAgWgMBMGA1UdJQQMMAoG 23 | CCsGAQUFBwMBMBQGA1UdEQQNMAuCCWxvY2FsaG9zdDANBgkqhkiG9w0BAQsFAAOC 24 | AgEAUbKo4czkbnjtcaSU0lClp3QdULOk7GHXPqwkGmRBxE//Z2xNgtkDa7k31XNv 25 | 9sMH1Y+GzL77JxKDMOYnLLlzOZisGfu7fdJUCb8+UR1JZjr382/V05+ngnlS4VQM 26 | ScIM4o7Fjxs6VLQHTo67IcfMY2XVa3xiSlYnZk7EqGxFM5rTlzNeD8clVBNSDMrZ 27 | 0JtHzremhTCA9Uy4e9fEJg2vr5j8IrDz2Gi4mkVOn+4oi6MeS2N8lRB0J26ONra7 28 | DdcK3b9zPf+1hlzxsDV/uge5qfD7dQQg1160yK8AsqQF2xZC1mGDPfqOJ3uswHt0 29 | by+Pg9f0FBMzZC/u033jE7+4kLuEqT/LBeW324f9euOZ2fz1GQUos3APZnvddz+G 30 | K3Q92lv7leepDlZpSSXIOp21cRNo3glymMRCa9VplRsUev4TqQYVUyqSzJF2BLVA 31 | 5j0mgJzFS2y5FlvgXsyj/QuO8wrAfFmD+7xjZzGNFhQjSCEMMGa/7zcassC3GWfs 32 | 4UVtySyGpIfpsfYHP/HPPM7LkbMlAklx0sKFUOUS82EV0AXHyC6wbR0f16TkPdH0 33 | 89RnP6NrWeOL2un5GPQB+yH7///oXkhMk6M2y/cHvGCBMC5FW/+zRkmdyEzJZWYm 34 | eATWqjETDTkgBu84NAO0YZ2FtHz2gc/xDeQeDY97Q8maIxU= 35 | -----END CERTIFICATE----- 36 | -------------------------------------------------------------------------------- /integration-tests/certs/broker-key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCqtRND1GELHgVf 3 | RSNBcvIeZ6o3ARieCKi7UGS13c8GAYJjpHId9FEOT6K2HhqsdsgAgmNK8LcY5NWM 4 | yNascwZN3oW+ftTiXTB5EhOgdOaOnREiVbvQcm6RIrQJQGp+Lbv3i3KUZzQ9ziTN 5 | u0OturKD2HADfZMMBCySTSZocws+tY3KykGrMeXsKuF+5WKlxBCJM4qWrC3izhzN 6 | LGsocwIkiqTXIaW79Tp0GpAB58j3QgR5rBCIcbDDtnAoLOuyQTkHakiCKT+kx6Dp 7 | SbtptgNseeAuZAm8AGIrifSEEiOSPrvLNsemdkyORK+lupyp4mulXRyyGp8WofnH 8 | 5qCGsrB/AgMBAAECggEAEeha9AOkhoEIuTzMfQIs6gmf7pM73OA1qyi81+ND43Jn 9 | FkLbAc9ubVznScmQrMTtKDiFaAgmfQMMb+9lrcOHRsXwK9KsTG7QNfMygeOhiBZs 10 | BLkPscc/WBRW5J2QTlpH3KkRRQYqkc09SSO67s+mCHS9E3Cp61nIvzQ+sjhXVqWT 11 | MqsT8vMkAvfYPd8S03PMbVnio1qa2fBAVAV9OQR0Emxy3Jhs1j7hwJcW+Za3LCLX 12 | 349Vwfpm9Z43BvLP3JQpy9PwR9w3shQpHh2KawPEcR/87OZGt4J0Lazce9E6ehlz 13 | p1fKzXot+Ib0mGCKxBR18q6W/dD8sUbh20bOphfVAQKBgQDVfmPHaS1uf514zEY2 14 | EaUsUEYg7w49PRsTIejoVl3rQ3zitEY4G8SAKvygXdqoaz/oZyitAIpNPfWhArAW 15 | S8Jl701U77HDklG/7rOpHu86ukWbf78mbpi5Pevl8eky2Y+KK6J+HDrkIxXszlwK 16 | 5SGKRzwbXhYzKcfV1Kv1JaNo/wKBgQDMseV3wxNJuyBfgsxtdkVl/EuCaHR9AhQ2 17 | +bo/qiPLXkwn5sjBt7v0W1TWtFXIv8Ql40CmPyzfx4sXHkUPgwR9OjtB/9k/JHNz 18 | fmDgyMcHEi76lgX6NfCNZ9zn7nrGXxioCupCtzbZLmpowQ9JsWtY7aezhrvnR4na 19 | lqwOlJ04gQKBgHeRMZCc9zTLhAYDYc8mUrteuef3+qGRd3hfpXF57V+1jFvrWuhR 20 | pNujN5kY9z0b087093LsuohICykBuFzEUTuFqmnHVGeTqvUzWqt9B758VD+ibAu6 21 | JQ6Z/2Po+BHihuF7TqYSaWkbvUvCxwnTCdXHz4IET6qX27OGSEgjrEFBAoGAWs7o 22 | 79J48hKz7+tE6aK4cuAUV4wjcXnEogbzm17NdmElA+acVWQ/W85QutdR3zdDu1Mv 23 | 0RDhxXzutZjWJmWHTk7RDxyDskFnfmsoa1BnCzoD4WNAz5myV+kl1Ta0/OAfPh1p 24 | g6NoD71Js6NCNv0glFkKNtik75uLCpAhUG6ZuQECgYEAyXGiSLsuMzdhW/IzInji 25 | kJ6kg1Ux6/BDyKSk2vJ0NS2QldexXlFQdqYLIgMJcdJHiY/9uQZd47zG2fbLLqBr 26 | OoyqmRqf9PkTvDJMSD/dkznryGWBvvTHsCU8CKxOnvp89sExR751kMdtZiJ/yxvw 27 | lTptjiYN7dVJ9kMewH/WJh4= 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /integration-tests/certs/cacert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIGDDCCA/SgAwIBAgIJAJnACyGkFss5MA0GCSqGSIb3DQEBCwUAMIGSMQswCQYD 3 | VQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEjMCEGA1UECgwaQXBhY2hlIFNv 4 | ZnR3YXJlIEZvdW5kYXRpb24xDzANBgNVBAsMBlB1bHNhcjESMBAGA1UEAwwJUHVs 5 | c2FyIENBMSQwIgYJKoZIhvcNAQkBFhVkZXZAcHVsc2FyLmFwYWNoZS5vcmcwHhcN 6 | MjEwNjIyMDU1NTM5WhcNNDEwNjE3MDU1NTM5WjCBkjELMAkGA1UEBhMCVVMxEzAR 7 | BgNVBAgMCkNhbGlmb3JuaWExIzAhBgNVBAoMGkFwYWNoZSBTb2Z0d2FyZSBGb3Vu 8 | ZGF0aW9uMQ8wDQYDVQQLDAZQdWxzYXIxEjAQBgNVBAMMCVB1bHNhciBDQTEkMCIG 9 | CSqGSIb3DQEJARYVZGV2QHB1bHNhci5hcGFjaGUub3JnMIICIjANBgkqhkiG9w0B 10 | AQEFAAOCAg8AMIICCgKCAgEAlvc1vIIKOAFomJh+kKJ1nWID5cLISNOEaRdLzTZo 11 | kOofm6uoWa8HkjxmuPmbnqGGxjnjnffMvuo8df6aj1VFokhVgUUYf3yN0gtlVCyd 12 | tWa9OMgWrKDoVqHcLCnl8giBuaC1RhDmmvYgHZDr260X/AfEaPmYq426bLAQYBxZ 13 | fqNu4sGHxbCEciFi0DvnZzWT++rs2+hgrPmqQFbLzojx4m4riJW1IWnIvKwnf/j8 14 | V+rWZy/DJDG/oQLl6eIyZ6oy8nxn+3PYq6NKavdeayLwT1HuckX1ooHA+/a+r+6J 15 | m1mEg5OwwQOP720gmgjC/8P3/xKyM6e0s01vKnllf1PbIwTrpzcFspaXzeEfAFpV 16 | ykyf/HTgTcid+Mj3zHL5isgN3qj5FjSG+CVjTpnO5mGtbXQI+jMmbKPU3ubFsVw3 17 | hrm6ZVDP4P+JvJBzs40usVNHJVtSZYJbGojx/tadQahpZuFPFuV8O5eYNwrRlC6M 18 | sKVX6IPT+lqXKQLzTtQNzxPDe8SJi+ca+5mQ1kf+VyQ5AkHM+cR/Pn49jFn3beA2 19 | GIVWoAS7SzUO5Sjle+NI1UnnY/6ZU6OnlsO5sCLp7nY1jWoirZQU+kX6/Wi4z2MH 20 | 7d6Nw0NZS87h3iNuTgVxgTDVVx7VNISeX9fi1mCkel4XPZ3VaSH9HDxlR0SihvtH 21 | 9IcCAwEAAaNjMGEwHQYDVR0OBBYEFJwSlUAQswluhzWF9O2pNXmyvc4IMB8GA1Ud 22 | IwQYMBaAFJwSlUAQswluhzWF9O2pNXmyvc4IMA8GA1UdEwEB/wQFMAMBAf8wDgYD 23 | VR0PAQH/BAQDAgGGMA0GCSqGSIb3DQEBCwUAA4ICAQAZgrrJdHgiQwWkJZFJtk+1 24 | iouKKlaz64Yx8Txk8Q49TJwDpCSmL8zk7H92oVlxtoA2IpSBAFIDyrGov/3/EaLc 25 | 6oyXYi2AKsYpTSZuLj2KP8HfB+TG8LHpER4Pv+WtX532V2A008hKyxSRUDWgI2tt 26 | F85GqpopwqDmDRsa06qCoBustrbDHDrjEWCld81qPZWOh07k7NRlX9t5D0a0sIOq 27 | lQaLnlI08fyxAK0GsJnvQIZ9/UVz0sB9OfEE2PHRSGAbAPzb49SpUrncLIV4rHTH 28 | DswtKEvaEpcmuXGIb+HI0ZgZnS56oiu83NbvSCMMSgqHvXdu65g8SYGUihy8NoaV 29 | Icr0jFfgbb21bhWgy7VyTnMbCRWEtJknPGzmi6/U9wnAmIYP0L9AXjbXkvysDmdd 30 | VoKT8HddPvgfZC7sgamMh0JxkzOHsO+C7DXw6kLp8FhoQPGk2/mK8McBfDY3g3hu 31 | meynM7GW6/7gkYXmuf1g3os+5iBHN4Rg0GL7RuXPrdypNKeVIrrq+D3b81LWuON3 32 | cFOKSX1R3Hto5mM3Zrt522KzzwJdIaEKyTazbdQWJXOuIHGGsk7CroJJxCkjSvSK 33 | U23R3i6Sld5HUYAGr0iBsf++7YNi3Z86KPovZHyUPdgUpW3Vk+jw9FJnWlkQYQxn 34 | VmnNXgp4FahF1fz8lTAddw== 35 | -----END CERTIFICATE----- 36 | -------------------------------------------------------------------------------- /integration-tests/certs/client-cert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIFZDCCA0ygAwIBAgICEAEwDQYJKoZIhvcNAQELBQAwgZIxCzAJBgNVBAYTAlVT 3 | MRMwEQYDVQQIDApDYWxpZm9ybmlhMSMwIQYDVQQKDBpBcGFjaGUgU29mdHdhcmUg 4 | Rm91bmRhdGlvbjEPMA0GA1UECwwGUHVsc2FyMRIwEAYDVQQDDAlQdWxzYXIgQ0Ex 5 | JDAiBgkqhkiG9w0BCQEWFWRldkBwdWxzYXIuYXBhY2hlLm9yZzAeFw0yMTA2MjIw 6 | NTU1MzlaFw0zMTA2MjAwNTU1MzlaMIGOMQswCQYDVQQGEwJVUzETMBEGA1UECAwK 7 | Q2FsaWZvcm5pYTEjMCEGA1UECgwaQXBhY2hlIFNvZnR3YXJlIEZvdW5kYXRpb24x 8 | DzANBgNVBAsMBlB1bHNhcjEOMAwGA1UEAwwFYWRtaW4xJDAiBgkqhkiG9w0BCQEW 9 | FWRldkBwdWxzYXIuYXBhY2hlLm9yZzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC 10 | AQoCggEBAM6DhhMRpatXj/+6TgI8nAH3gbx6O8onimBAb99SyoJUfxpSePMjQQh2 11 | C+SwDc/SxWHYoer38gRvPDmObrPc0Nsa17+ppmpGPGG/9WQFiVKyXXEABgQAjRMc 12 | OJJBTEojdZ2WffWhlulo/7GOD/hSCZ8nb/7DIk0MWtZ3XwKrEnoeojrC7cjLM1HT 13 | odtYW45Fq/NsC/YBl5w0muhTsI6jHC54hUGllvD/GIRzSCfbXFVR23oHgdgoFWc8 14 | YTcd1pP7nzq3ZhNTLLvXprJDW8lhExHiZlUIUTViZZmfaBfXiOw1tJvvsZ+r1CUh 15 | QJoOGW4R7tj6VpENyey7pH2Er7jiTQUCAwEAAaOBxTCBwjAJBgNVHRMEAjAAMBEG 16 | CWCGSAGG+EIBAQQEAwIFoDAzBglghkgBhvhCAQ0EJhYkT3BlblNTTCBHZW5lcmF0 17 | ZWQgQ2xpZW50IENlcnRpZmljYXRlMB0GA1UdDgQWBBRZgXK4DZrHLR7CmORj2ies 18 | IC9lRDAfBgNVHSMEGDAWgBScEpVAELMJboc1hfTtqTV5sr3OCDAOBgNVHQ8BAf8E 19 | BAMCBeAwHQYDVR0lBBYwFAYIKwYBBQUHAwIGCCsGAQUFBwMEMA0GCSqGSIb3DQEB 20 | CwUAA4ICAQAPuXzTjW+84f3boomOvGNS57lSPyx83SNXXvtXW4VudkhCMc2pggkT 21 | OY2bizRVny5uGE7eHo7a7dBoujHiAk+5lN7KNlY/VZpX6qRg0Ps5JUTfZSFYSdL+ 22 | ZXFhOwFgDqlLVWlUXaJ4PiABjcZks4tWZ66Yg+BNI2MU5PJGySOoAuntM53x4hA7 23 | xHmyX7nsmqUDA7C4TbUKr+R9KmPhPQhJwcC1mFwhJtIbVoxn4E7lSr6BsNQuZ6aJ 24 | aDjh8qxqJpmL9dYqle9fuP1naJfKOLcOdAudAgIsjpQTWbGn8lPUGIke488NlECq 25 | LYEi47GLMrW4CcD4Z4lvDRKCtO6HYsv+AOuyN0O3iALOyg8+khqDufqBZQWSq8GI 26 | jpCDd+0zNzHCDEmSMgzo8wmA9LeRpEzH6d3v35gjJB8yFC3IygQrKGIqkF/FkTuw 27 | ZcZhK8Tjb/5wrgSq8jm9pQbvm6iMTbor+E7bOS+9jepCTc0C/TgLyxxcJu4GraGA 28 | wjOY7MhVFPkz1agp0gj6YvtMlPDS8AgQjn4RxW1aCWuqWH0p5g1XOoGyDqWorhX+ 29 | uzr5LjBjAOX931MFG0nHNefaLEfWaooKDH0HiAfpHzfvOwes4j47WquFzpPR+n4d 30 | Sr1cdPEqBHWmqLtQyZqnAgB3c1vgwpig907lHY/L2t38xwvFAENY8A== 31 | -----END CERTIFICATE----- 32 | -------------------------------------------------------------------------------- /integration-tests/certs/client-key.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDOg4YTEaWrV4// 3 | uk4CPJwB94G8ejvKJ4pgQG/fUsqCVH8aUnjzI0EIdgvksA3P0sVh2KHq9/IEbzw5 4 | jm6z3NDbGte/qaZqRjxhv/VkBYlSsl1xAAYEAI0THDiSQUxKI3Wdln31oZbpaP+x 5 | jg/4UgmfJ2/+wyJNDFrWd18CqxJ6HqI6wu3IyzNR06HbWFuORavzbAv2AZecNJro 6 | U7COoxwueIVBpZbw/xiEc0gn21xVUdt6B4HYKBVnPGE3HdaT+586t2YTUyy716ay 7 | Q1vJYRMR4mZVCFE1YmWZn2gX14jsNbSb77Gfq9QlIUCaDhluEe7Y+laRDcnsu6R9 8 | hK+44k0FAgMBAAECggEAf2VZl3fieJHazkozB2Q2ZWw3R3ssWSgNUBVQLjdXoBDa 9 | G/XWkT8lRj/0VE5bJuKCSzsln9r3HM82GteH6UMGQLQNdjoE5DiR1Udi7SIRNce8 10 | pxH5pAxm+uwE5gyMMIwxaVbGO3pEq5bPbcwShACv2NOuXj4ocdl2TCl1niLEkjop 11 | X7Kj8jswsBb/zF8ItmW0rEpGoZXWyToh06fknONsAe0z0spXwZTHRFVxVn8oVmuN 12 | RwF3Fjjtdfsi9BE+jJEzrpOzfZSgjT44hbWSfe7LVEfLVQN4CqyKo2mLzWAC6hWZ 13 | /2o5KmJeGkR4ylTOXSmb92a7dGN218KjPgrI/C3fQQKBgQD06kxfkn3cT7wuIWv0 14 | hcSLKYGPlSh3UxiC8F4V3FFtGwAmfiXXnBgDslWtxyp1b9UxSRSR2OmGELVFzFW2 15 | XpB4VTE8jAu2ktpAnjpzaCg2izhFQYeo4rK/ebA46Pl9/A8tE5Jm+JWDf7Il6J7m 16 | +MSswi4OuMm6WPm6cm6MugiUUQKBgQDX3EnG+UkFm36o0ybL5PJz+TEQVbNg0MM4 17 | 8O0cev0zqvOQAiQs9Afu5A5oeZKvruyPoYKCu4XJBh5+va+/7JNnSFv1W0h2EOKQ 18 | mULm7TDs+FGFOcgDcnnRX4n6KJ5nRaFj8jxMObwmOtlBSdZuWoem4Hh2tTMDbkmX 19 | hOwI00FEdQKBgERB3GEyeaNiEYclx2mRsnI6ciJrJqkC3qz3grFDAuqOgN85fyB1 20 | H3hARoK1JE8wiNFAldwEASldFLhMN4MpHch7rco7GbSbfvpNXur1F2gEKv2aQs29 21 | yKV2q7dgrs/+5NfiQYYzN7A7cZIBH/AtWtrvD1kJBSfLTmY5KDhOTL/RAoGBAKQc 22 | 5TKToILU3403S83EuNiXYkgLAB/hWCtYcM0wbIT1ucuI9TwAJG/pj1K6610KXuws 23 | XO9L5sEZF+JAEPiXwtHJX7DAv+yTlc1d2FF9j676c/AYKAsG47rdKie47gWSGMvG 24 | BTXmxzdBkp9ipdasmWm0S6HkzW4UUXsTIejrxDlpAoGAF1aDHgC0ZCjNEuUYiyOM 25 | oRkANY2DmjpQjQnX6zDmq+6+HITDM0g76PQS2igvB06Ysym+o997b1FcDot1ml4L 26 | 9/10z9TcRVZiKbbF7e9h75QvmtGv2rR6Ucc+yOpJUsBX+vSpnQlUGT6y9qrF0dr/ 27 | YjVcFUPAwA0nqNZvQfdcH14= 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /integration-tests/conf/.htpasswd: -------------------------------------------------------------------------------- 1 | admin:$apr1$FG4AO6aX$KGYPuMoLUou3i6vUkPUUf. 2 | -------------------------------------------------------------------------------- /integration-tests/conf/client.conf: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | # Pulsar Client configuration 21 | webServiceUrl=https://localhost:8443/ 22 | brokerServiceUrl=pulsar+ssl://localhost:6651/ 23 | tlsAllowInsecureConnection=false 24 | tlsTrustCertsFilePath=/pulsar/certs/cacert.pem 25 | authPlugin=org.apache.pulsar.client.impl.auth.AuthenticationTls 26 | authParams=tlsCertFile:/pulsar/certs/client-cert.pem,tlsKeyFile:/pulsar/certs/client-key.pem 27 | 28 | -------------------------------------------------------------------------------- /integration-tests/pb/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | 19 | 20 | PROJECT_DIR=$(git rev-parse --show-toplevel) 21 | SOURCE_PATH="$PROJECT_DIR/integration-tests/pb" 22 | DEST_PATH="$PROJECT_DIR/integration-tests/pb" 23 | echo "source_path: $SOURCE_PATH" 24 | echo "dest_path: $DEST_PATH" 25 | protoc -I=$SOURCE_PATH --go_out=$DEST_PATH $SOURCE_PATH/*.proto 26 | -------------------------------------------------------------------------------- /integration-tests/pb/hello.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | syntax = "proto3"; 21 | package prototest; 22 | 23 | option go_package = "."; 24 | 25 | import "hi.proto"; 26 | 27 | message Test { 28 | int32 num = 1; 29 | string msf = 2; 30 | Foo foo = 3; 31 | HiContent hiContent = 4; 32 | } 33 | 34 | message Foo { 35 | string name = 1; 36 | int32 value = 2; 37 | repeated string names = 3; 38 | } 39 | -------------------------------------------------------------------------------- /integration-tests/pb/hi.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | syntax = "proto3"; 21 | package prototest; 22 | 23 | option go_package = "."; 24 | 25 | message HiContent { 26 | int32 id = 2; 27 | string content = 1; 28 | } 29 | -------------------------------------------------------------------------------- /integration-tests/tokens/admin-token: -------------------------------------------------------------------------------- 1 | eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiJ9.MKSR5Mb2wu_FQlMYACv2i4ubMCn4h4Dj_aIDo1dPsDk -------------------------------------------------------------------------------- /integration-tests/tokens/secret.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/pulsar-client-go/ad9a7d1f349b7e0eb6eb05eb315dd8a10d93dc98/integration-tests/tokens/secret.key -------------------------------------------------------------------------------- /integration-tests/tokens/token.txt: -------------------------------------------------------------------------------- 1 | eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ0b2tlbi1wcmluY2lwYWwifQ.tSfgR8l7dKC6LoWCxQgNkuSB8our7xV_nAM7wpgCbG4 2 | -------------------------------------------------------------------------------- /licenserc.toml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | headerPath = "Apache-2.0-ASF.txt" 19 | 20 | excludes = [ 21 | "*.txt", 22 | ] 23 | 24 | [mapping.DOUBLESLASH_STYLE] 25 | extensions = ["go"] 26 | -------------------------------------------------------------------------------- /oauth2/data_url.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package oauth2 19 | 20 | import ( 21 | "encoding/base64" 22 | "errors" 23 | "regexp" 24 | ) 25 | 26 | var errDataURLInvalid = errors.New("invalid data URL") 27 | 28 | // https://datatracker.ietf.org/doc/html/rfc2397 29 | var dataURLRegex = regexp.MustCompile("^data:(?P[^;,]+)?(;(?Pcharset=[^;,]+))?" + 30 | "(;(?Pbase64))?,(?P.+)") 31 | 32 | type dataURL struct { 33 | url string 34 | Mimetype string 35 | Data []byte 36 | } 37 | 38 | func newDataURL(url string) (*dataURL, error) { 39 | if !dataURLRegex.Match([]byte(url)) { 40 | return nil, errDataURLInvalid 41 | } 42 | 43 | match := dataURLRegex.FindStringSubmatch(url) 44 | if len(match) != 7 { 45 | return nil, errDataURLInvalid 46 | } 47 | 48 | dataURL := &dataURL{ 49 | url: url, 50 | } 51 | 52 | mimetype := match[dataURLRegex.SubexpIndex("mimetype")] 53 | if mimetype == "" { 54 | mimetype = "text/plain" 55 | } 56 | dataURL.Mimetype = mimetype 57 | 58 | data := match[dataURLRegex.SubexpIndex("data")] 59 | if match[dataURLRegex.SubexpIndex("base64")] == "" { 60 | dataURL.Data = []byte(data) 61 | } else { 62 | data, err := base64.StdEncoding.DecodeString(data) 63 | if err != nil { 64 | return nil, err 65 | } 66 | dataURL.Data = data 67 | } 68 | 69 | return dataURL, nil 70 | } 71 | -------------------------------------------------------------------------------- /oauth2/data_url_test.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package oauth2 19 | 20 | import ( 21 | "encoding/base64" 22 | "testing" 23 | 24 | "github.com/stretchr/testify/assert" 25 | "github.com/stretchr/testify/require" 26 | ) 27 | 28 | func TestNewDataURL(t *testing.T) { 29 | rawURL := "data:,test" 30 | url, err := newDataURL(rawURL) 31 | require.NoError(t, err) 32 | assert.Equal(t, "text/plain", url.Mimetype) 33 | assert.Equal(t, "test", string(url.Data)) 34 | 35 | rawURL = "data:;base64," + base64.StdEncoding.EncodeToString([]byte("test")) 36 | url, err = newDataURL(rawURL) 37 | require.NoError(t, err) 38 | assert.Equal(t, "text/plain", url.Mimetype) 39 | assert.Equal(t, "test", string(url.Data)) 40 | 41 | rawURL = "data:application/json,test" 42 | url, err = newDataURL(rawURL) 43 | require.NoError(t, err) 44 | assert.Equal(t, "application/json", url.Mimetype) 45 | assert.Equal(t, "test", string(url.Data)) 46 | 47 | rawURL = "data:application/json;base64," + base64.StdEncoding.EncodeToString([]byte("test")) 48 | url, err = newDataURL(rawURL) 49 | require.NoError(t, err) 50 | assert.Equal(t, "application/json", url.Mimetype) 51 | assert.Equal(t, "test", string(url.Data)) 52 | 53 | rawURL = "data://test" 54 | url, err = newDataURL(rawURL) 55 | require.Nil(t, url) 56 | assert.Error(t, err) 57 | assert.EqualError(t, errDataURLInvalid, err.Error()) 58 | } 59 | -------------------------------------------------------------------------------- /oauth2/oidc_endpoint_provider.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package oauth2 19 | 20 | import ( 21 | "encoding/json" 22 | "net/http" 23 | "net/url" 24 | "path" 25 | 26 | "github.com/pkg/errors" 27 | ) 28 | 29 | // OIDCWellKnownEndpoints holds the well known OIDC endpoints 30 | type OIDCWellKnownEndpoints struct { 31 | AuthorizationEndpoint string `json:"authorization_endpoint"` 32 | TokenEndpoint string `json:"token_endpoint"` 33 | DeviceAuthorizationEndpoint string `json:"device_authorization_endpoint"` 34 | } 35 | 36 | // GetOIDCWellKnownEndpointsFromIssuerURL gets the well known endpoints for the 37 | // passed in issuer url 38 | func GetOIDCWellKnownEndpointsFromIssuerURL(issuerURL string) (*OIDCWellKnownEndpoints, error) { 39 | u, err := url.Parse(issuerURL) 40 | if err != nil { 41 | return nil, errors.Wrap(err, "could not parse issuer url to build well known endpoints") 42 | } 43 | u.Path = path.Join(u.Path, ".well-known/openid-configuration") 44 | 45 | r, err := http.Get(u.String()) 46 | if err != nil { 47 | return nil, errors.Wrapf(err, "could not get well known endpoints from url %s", u.String()) 48 | } 49 | defer r.Body.Close() 50 | 51 | var wkEndpoints OIDCWellKnownEndpoints 52 | err = json.NewDecoder(r.Body).Decode(&wkEndpoints) 53 | if err != nil { 54 | return nil, errors.Wrap(err, "could not decode json body when getting well known endpoints") 55 | } 56 | 57 | return &wkEndpoints, nil 58 | } 59 | -------------------------------------------------------------------------------- /oauth2/store/store.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package store 19 | 20 | import ( 21 | "errors" 22 | 23 | "github.com/apache/pulsar-client-go/oauth2" 24 | ) 25 | 26 | // ErrNoAuthenticationData indicates that stored authentication data is not available 27 | var ErrNoAuthenticationData = errors.New("authentication data is not available") 28 | 29 | // ErrUnsupportedAuthData indicates that stored authentication data is unusable 30 | var ErrUnsupportedAuthData = errors.New("authentication data is not usable") 31 | 32 | // Store is responsible for persisting authorization grants 33 | type Store interface { 34 | // SaveGrant stores an authorization grant for a given audience 35 | SaveGrant(audience string, grant oauth2.AuthorizationGrant) error 36 | 37 | // LoadGrant loads an authorization grant for a given audience 38 | LoadGrant(audience string) (*oauth2.AuthorizationGrant, error) 39 | 40 | // WhoAmI returns the current user name (or an error if nobody is logged in) 41 | WhoAmI(audience string) (string, error) 42 | 43 | // Logout deletes all stored credentials 44 | Logout() error 45 | } 46 | -------------------------------------------------------------------------------- /pulsar/auth/disabled.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package auth 19 | 20 | import ( 21 | "crypto/tls" 22 | "net/http" 23 | ) 24 | 25 | type disabled struct{} 26 | 27 | // NewAuthDisabled return a interface of Provider 28 | func NewAuthDisabled() Provider { 29 | return &disabled{} 30 | } 31 | 32 | func (disabled) Init() error { 33 | return nil 34 | } 35 | 36 | func (disabled) GetData() ([]byte, error) { 37 | return nil, nil 38 | } 39 | 40 | func (disabled) Name() string { 41 | return "" 42 | } 43 | 44 | func (disabled) GetTLSCertificate() (*tls.Certificate, error) { 45 | return nil, nil 46 | } 47 | 48 | func (disabled) Close() error { 49 | return nil 50 | } 51 | 52 | func (d disabled) RoundTrip(_ *http.Request) (*http.Response, error) { 53 | return nil, nil 54 | } 55 | 56 | func (d disabled) Transport() http.RoundTripper { 57 | return nil 58 | } 59 | 60 | func (d disabled) WithTransport(_ http.RoundTripper) error { 61 | return nil 62 | } 63 | -------------------------------------------------------------------------------- /pulsar/batcher_builder.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package pulsar 19 | 20 | import ( 21 | "github.com/apache/pulsar-client-go/pulsar/internal" 22 | ) 23 | 24 | type BatcherBuilderType int 25 | 26 | const ( 27 | DefaultBatchBuilder BatcherBuilderType = iota 28 | KeyBasedBatchBuilder 29 | ) 30 | 31 | func GetBatcherBuilderProvider(typ BatcherBuilderType) ( 32 | internal.BatcherBuilderProvider, error, 33 | ) { 34 | switch typ { 35 | case DefaultBatchBuilder: 36 | return internal.NewBatchBuilder, nil 37 | case KeyBasedBatchBuilder: 38 | return internal.NewKeyBasedBatchBuilder, nil 39 | default: 40 | return nil, newError(InvalidBatchBuilderType, "unsupported batcher builder provider type") 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /pulsar/client_impl_with_slog_test.go: -------------------------------------------------------------------------------- 1 | /// Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | //go:build go1.21 19 | 20 | package pulsar 21 | 22 | import ( 23 | "log/slog" 24 | "os" 25 | "testing" 26 | 27 | "github.com/apache/pulsar-client-go/pulsar/log" 28 | "github.com/stretchr/testify/assert" 29 | ) 30 | 31 | func TestClientWithSlog(t *testing.T) { 32 | sLogger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug})) 33 | 34 | client, err := NewClient(ClientOptions{ 35 | URL: serviceURL, 36 | Logger: log.NewLoggerWithSlog(sLogger), 37 | }) 38 | assert.NotNil(t, client) 39 | assert.Nil(t, err) 40 | 41 | producer, err := client.CreateProducer(ProducerOptions{ 42 | Topic: newTopicName(), 43 | }) 44 | assert.NotNil(t, producer) 45 | assert.Nil(t, err) 46 | 47 | producer.Close() 48 | client.Close() 49 | } 50 | -------------------------------------------------------------------------------- /pulsar/consumer_interceptor.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package pulsar 19 | 20 | type ConsumerInterceptor interface { 21 | // BeforeConsume This is called just before the message is send to Consumer's ConsumerMessage channel. 22 | BeforeConsume(message ConsumerMessage) 23 | 24 | // OnAcknowledge This is called consumer sends the acknowledgment to the broker. 25 | OnAcknowledge(consumer Consumer, msgID MessageID) 26 | 27 | // OnNegativeAcksSend This method will be called when a redelivery from a negative acknowledge occurs. 28 | OnNegativeAcksSend(consumer Consumer, msgIDs []MessageID) 29 | } 30 | 31 | type ConsumerInterceptors []ConsumerInterceptor 32 | 33 | func (x ConsumerInterceptors) BeforeConsume(message ConsumerMessage) { 34 | for i := range x { 35 | x[i].BeforeConsume(message) 36 | } 37 | } 38 | 39 | func (x ConsumerInterceptors) OnAcknowledge(consumer Consumer, msgID MessageID) { 40 | for i := range x { 41 | x[i].OnAcknowledge(consumer, msgID) 42 | } 43 | } 44 | 45 | func (x ConsumerInterceptors) OnNegativeAcksSend(consumer Consumer, msgIDs []MessageID) { 46 | for i := range x { 47 | x[i].OnNegativeAcksSend(consumer, msgIDs) 48 | } 49 | } 50 | 51 | var defaultConsumerInterceptors = make(ConsumerInterceptors, 0) 52 | -------------------------------------------------------------------------------- /pulsar/crypto/crypto_failure_action.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package crypto 19 | 20 | const ( 21 | // ProducerCryptoFailureActionFail this is the default option to fail send if crypto operation fails. 22 | ProducerCryptoFailureActionFail = iota 23 | 24 | // ProducerCryptoFailureActionSend ignore crypto failure and proceed with sending unencrypted message. 25 | ProducerCryptoFailureActionSend 26 | ) 27 | 28 | const ( 29 | // ConsumerCryptoFailureActionFail this is the default option to fail consume messages until crypto succeeds. 30 | ConsumerCryptoFailureActionFail = iota 31 | 32 | // ConsumerCryptoFailureActionDiscard message is silently acknowledged and not delivered to the application 33 | ConsumerCryptoFailureActionDiscard 34 | 35 | // ConsumerCryptoFailureActionConsume deliver the encrypted message to the application. 36 | // It's the application's responsibility to decrypt the message. 37 | // if message is also compressed, decompression will fail. 38 | // If message contain batch messages, client will not be able to retrieve 39 | // individual messages in the batch. 40 | // delivered encrypted message contains EncryptionContext which contains encryption 41 | // and compression information in it using which application can decrypt the payload. 42 | ConsumerCryptoFailureActionConsume 43 | ) 44 | -------------------------------------------------------------------------------- /pulsar/crypto/crypto_key_reader.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package crypto 19 | 20 | // KeyReader implement this interface to read and provide public & private keys 21 | // key pair can be RSA, ECDSA 22 | type KeyReader interface { 23 | // PublicKey get public key that is be used by the producer to encrypt data key 24 | PublicKey(keyName string, metadata map[string]string) (*EncryptionKeyInfo, error) 25 | 26 | // PrivateKey get private key that is used by the consumer to decrypt data key 27 | PrivateKey(keyName string, metadata map[string]string) (*EncryptionKeyInfo, error) 28 | } 29 | -------------------------------------------------------------------------------- /pulsar/crypto/default_crypto_Key_reader.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package crypto 19 | 20 | import "os" 21 | 22 | // FileKeyReader default implementation of KeyReader 23 | type FileKeyReader struct { 24 | publicKeyPath string 25 | privateKeyPath string 26 | } 27 | 28 | func NewFileKeyReader(publicKeyPath, privateKeyPath string) *FileKeyReader { 29 | return &FileKeyReader{ 30 | publicKeyPath: publicKeyPath, 31 | privateKeyPath: privateKeyPath, 32 | } 33 | } 34 | 35 | // PublicKey read public key from the given path 36 | func (d *FileKeyReader) PublicKey(keyName string, keyMeta map[string]string) (*EncryptionKeyInfo, error) { 37 | return readKey(keyName, d.publicKeyPath, keyMeta) 38 | } 39 | 40 | // PrivateKey read private key from the given path 41 | func (d *FileKeyReader) PrivateKey(keyName string, keyMeta map[string]string) (*EncryptionKeyInfo, error) { 42 | return readKey(keyName, d.privateKeyPath, keyMeta) 43 | } 44 | 45 | func readKey(keyName, path string, keyMeta map[string]string) (*EncryptionKeyInfo, error) { 46 | key, err := os.ReadFile(path) 47 | if err != nil { 48 | return nil, err 49 | } 50 | return NewEncryptionKeyInfo(keyName, key, keyMeta), nil 51 | } 52 | -------------------------------------------------------------------------------- /pulsar/crypto/encryption_key_Info.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package crypto 19 | 20 | // EncryptionKeyInfo 21 | type EncryptionKeyInfo struct { 22 | metadata map[string]string 23 | key []byte 24 | name string 25 | } 26 | 27 | // NewEncryptionKeyInfo create a new EncryptionKeyInfo 28 | func NewEncryptionKeyInfo(name string, key []byte, metadata map[string]string) *EncryptionKeyInfo { 29 | return &EncryptionKeyInfo{ 30 | metadata: metadata, 31 | name: name, 32 | key: key, 33 | } 34 | } 35 | 36 | // Name get the name of the key 37 | func (eci *EncryptionKeyInfo) Name() string { 38 | return eci.name 39 | } 40 | 41 | // Key get the key data 42 | func (eci *EncryptionKeyInfo) Key() []byte { 43 | return eci.key 44 | } 45 | 46 | // Metadata get key metadata 47 | func (eci *EncryptionKeyInfo) Metadata() map[string]string { 48 | return eci.metadata 49 | } 50 | -------------------------------------------------------------------------------- /pulsar/crypto/message_crypto.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package crypto 19 | 20 | // MessageCrypto implement this interface to encrypt and decrypt messages 21 | type MessageCrypto interface { 22 | 23 | // AddPublicKeyCipher encrypt data using the public key(s) in the argument. 24 | // If more than one key name is specified, data key is encrypted using each of those keys. 25 | // If the public key is expired or changed, application is responsible to remove 26 | // the old key and add the new key. 27 | AddPublicKeyCipher(keyNames []string, keyReader KeyReader) error 28 | 29 | // RemoveKeyCipher remove the key from the list 30 | RemoveKeyCipher(keyName string) bool 31 | 32 | // Encrypt the payload using the data key and update 33 | // message metadata with the key and encrypted data key 34 | Encrypt(encKeys []string, KeyReader KeyReader, msgMetadata MessageMetadataSupplier, payload []byte) ([]byte, error) 35 | 36 | // Decrypt the payload using the data key. 37 | // Keys used to encrypt the data key can be retrieved from msgMetadata 38 | Decrypt(msgMetadata MessageMetadataSupplier, payload []byte, KeyReader KeyReader) ([]byte, error) 39 | } 40 | -------------------------------------------------------------------------------- /pulsar/crypto/testdata/pub_key_rsa.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEA5YeHRDCRtEn8kVi7xVT2 3 | YicRByZZUPjzB9qSlQboHvdIpZhWhoRg+qPYP2RoH7JlmPX/q/RnNjFZ52pG9Tzl 4 | 3J67Pz3H5j4FoKFZ7OTf55Wk2f83pe9hgDTfAfIuR1ch2MtfOx1yzoVUENFfLwiI 5 | hSg/+6wjY98SbZujM1a/iWpM9IFkpOgwZZrXtSPoUlNidwAZrYS+eGVL9hyyH9RT 6 | 86gYh1BgsVH4zjQqCP76lxXrsSynlsXfasenpTppVfvyR1NhK1JhQf3dsvCgie0i 7 | WcK+OICt0z9WesakKnyAU01BFOmXAPuDS2wErTb2Zw654lo7iEFdRGK1Mmx0gViJ 8 | 7bXBxKVIw24za/EsCeb+jLFXVilC/P0T7mI/y6FF0wPkTf8aICJphspdnimEJSXe 9 | Qinjmx+iFWvG/uHimrswXaAQbP1YOoJZx+HFy4b/4/hVLu3aiFM2sgfGkT8gsg3d 10 | i2zxEIn7cnLaIC4HgcVxQLUVMsBXFXgU2SWVWPb2+fv9AgMBAAE= 11 | -----END PUBLIC KEY----- -------------------------------------------------------------------------------- /pulsar/crypto/testdata/truncated_pub_key_rsa.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEA5YeHRDCRtEn8kVi7xVT2 3 | YicRByZZUPjzB9qSlQboHvdIpZhWhoRg+qPYP2RoH7JlmPX/q/RnNjFZ52pG9Tzl 4 | 3J67Pz3H5j4FoKFZ7OTf55Wk2f83pe9hgDTfAfIuR1ch2MtfOx1yzoVUENFfLwiI 5 | hSg/+6wjY98SbZujM1a/iWpM9IFkpOgwZZrXtSPoUlNidwAZrYS+eGVL9hyyH9RT 6 | 86gYh1BgsVH4zjQqCP76lxXrsSynlsXfasenpTppVfvyR1NhK1JhQf3dsvCgie0i 7 | WcK+OICt0z9WesakKnyAU01BFOmXAPuDS2wErTb2Zw654lo7iEFdRGK1Mmx0gViJ 8 | 7bXBxKVIw24za/EsCeb+jLFXVilC/P0T7mI/y6FF0wPkTf8aICJphspdnimEJSXe 9 | Qinjmx+iFWvG/uHimrswXaAQbP1YOoJZx+HFy4b/4/hVLu3aiFM2sgfGkT8gsg3d 10 | -----END PUBLIC KEY----- -------------------------------------------------------------------------------- /pulsar/crypto/testdata/wrong_encode_pub_key_rsa.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN PUBLIC KEY----- 2 | MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEA5YeHRDCRtEn8kVi7xVT2 3 | YicRByZZUPjzB9qSlQboHvdIpZhWhoRg+qPYP2RoH7JlmPX/q/RnNjFZ52pG9Tzl 4 | 3J67Pz3H5j4FoKFZ7OTf55Wk2f83pe9hgDTfAfIuR1ch2MtfOx1yzoVUENFfLwiI 5 | hSg/+6wjY98SbZujM1a/iWpM9IFkpOgwZZrXtSPoUlNidwAZrYS+eGVL9hyyH9RT 6 | 86gYh1BgsVH4zjQqCP76lxXrsSynlsXfasenpTppVfvyR1NhK1JhQf3dsvCgie0i 7 | WcK+OICt0z9WesakKnyAU01BFOmXAPuDS2wErTb2Zw654lo7iEFdRGK1Mmx0gViJ 8 | 7bXBxKVIw24za/EsCeb+jLFXVilC/P0T7mI/y6FF0wPkTf8aICJphspdnimEJSXe 9 | Qinjmx+iFWvG/uHimrswXaAQbP1YOoJZx+HFy4b/4/hVLu3aiFM2sgfGkT8gsg3d -------------------------------------------------------------------------------- /pulsar/default_router_bench_test.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package pulsar 19 | 20 | import ( 21 | "testing" 22 | "time" 23 | 24 | "github.com/apache/pulsar-client-go/pulsar/internal" 25 | ) 26 | 27 | var ( 28 | targetPartition int 29 | ) 30 | 31 | func BenchmarkDefaultRouter(b *testing.B) { 32 | const numPartitions = uint32(200) 33 | msg := &ProducerMessage{ 34 | Payload: []byte("message 1"), 35 | } 36 | router := newBenchDefaultRouter() 37 | b.ResetTimer() 38 | for i := 0; i < b.N; i++ { 39 | targetPartition = router(msg, numPartitions) 40 | } 41 | } 42 | 43 | func BenchmarkDefaultRouterParallel(b *testing.B) { 44 | const numPartitions = uint32(200) 45 | msg := &ProducerMessage{ 46 | Payload: []byte("message 1"), 47 | } 48 | router := newBenchDefaultRouter() 49 | b.ResetTimer() 50 | b.RunParallel(func(pb *testing.PB) { 51 | for pb.Next() { 52 | targetPartition = router(msg, numPartitions) 53 | } 54 | }) 55 | } 56 | 57 | func newBenchDefaultRouter() func(*ProducerMessage, uint32) int { 58 | const ( 59 | maxBatchingMessages = 2000 60 | maxBatchingSize = 524288 61 | maxBatchingDelay = 100 * time.Millisecond 62 | ) 63 | return NewDefaultRouter(internal.JavaStringHash, maxBatchingMessages, maxBatchingSize, maxBatchingDelay, false) 64 | } 65 | -------------------------------------------------------------------------------- /pulsar/encryption.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package pulsar 19 | 20 | import "github.com/apache/pulsar-client-go/pulsar/crypto" 21 | 22 | // ProducerEncryptionInfo encryption related fields required by the producer 23 | type ProducerEncryptionInfo struct { 24 | // KeyReader read RSA public/private key pairs 25 | KeyReader crypto.KeyReader 26 | 27 | // MessageCrypto used to encrypt and decrypt the data and session keys 28 | MessageCrypto crypto.MessageCrypto 29 | 30 | // Keys list of encryption key names to encrypt session key 31 | Keys []string 32 | 33 | // ProducerCryptoFailureAction action to be taken on failure of message encryption 34 | // default is ProducerCryptoFailureActionFail 35 | ProducerCryptoFailureAction int 36 | } 37 | 38 | // MessageDecryptionInfo encryption related fields required by the consumer to decrypt the message 39 | type MessageDecryptionInfo struct { 40 | // KeyReader read RSA public/private key pairs 41 | KeyReader crypto.KeyReader 42 | 43 | // MessageCrypto used to encrypt and decrypt the data and session keys 44 | MessageCrypto crypto.MessageCrypto 45 | 46 | // ConsumerCryptoFailureAction action to be taken on failure of message decryption 47 | ConsumerCryptoFailureAction int 48 | } 49 | -------------------------------------------------------------------------------- /pulsar/error_test.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package pulsar 19 | 20 | import ( 21 | "errors" 22 | "testing" 23 | 24 | "github.com/stretchr/testify/assert" 25 | ) 26 | 27 | func Test_joinErrors(t *testing.T) { 28 | err1 := errors.New("err1") 29 | err2 := errors.New("err2") 30 | err3 := errors.New("err3") 31 | err := errors.Join(ErrInvalidMessage, err1, err2) 32 | assert.True(t, errors.Is(err, ErrInvalidMessage)) 33 | assert.True(t, errors.Is(err, err1)) 34 | assert.True(t, errors.Is(err, err2)) 35 | assert.False(t, errors.Is(err, err3)) 36 | } 37 | -------------------------------------------------------------------------------- /pulsar/helper_test.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package pulsar 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/stretchr/testify/assert" 24 | ) 25 | 26 | func TestToKeyValues(t *testing.T) { 27 | meta := map[string]string{ 28 | "key1": "value1", 29 | } 30 | 31 | kvs := toKeyValues(meta) 32 | assert.Equal(t, 1, len(kvs)) 33 | assert.Equal(t, "key1", *kvs[0].Key) 34 | assert.Equal(t, "value1", *kvs[0].Value) 35 | 36 | meta = map[string]string{ 37 | "key1": "value1", 38 | "key2": "value2", 39 | } 40 | kvs = toKeyValues(meta) 41 | assert.Equal(t, 2, len(kvs)) 42 | for _, kv := range kvs { 43 | v := meta[*kv.Key] 44 | assert.Equal(t, v, *kv.Value) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /pulsar/internal/buffer_test.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package internal 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/stretchr/testify/assert" 24 | ) 25 | 26 | func TestBuffer(t *testing.T) { 27 | b := NewBuffer(1024) 28 | assert.Equal(t, uint32(0), b.ReadableBytes()) 29 | assert.Equal(t, uint32(1024), b.WritableBytes()) 30 | assert.Equal(t, uint32(1024), b.Capacity()) 31 | 32 | b.Write([]byte("hello")) 33 | assert.Equal(t, uint32(5), b.ReadableBytes()) 34 | assert.Equal(t, uint32(1019), b.WritableBytes()) 35 | assert.Equal(t, uint32(1024), b.Capacity()) 36 | } 37 | -------------------------------------------------------------------------------- /pulsar/internal/channel_cond_test.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package internal 19 | 20 | import ( 21 | "context" 22 | "sync" 23 | "testing" 24 | "time" 25 | ) 26 | 27 | func TestChCond(_ *testing.T) { 28 | cond := newCond(&sync.Mutex{}) 29 | wg := sync.WaitGroup{} 30 | wg.Add(1) 31 | go func() { 32 | cond.L.Lock() 33 | cond.wait() 34 | cond.L.Unlock() 35 | wg.Done() 36 | }() 37 | time.Sleep(10 * time.Millisecond) 38 | cond.broadcast() 39 | wg.Wait() 40 | } 41 | 42 | func TestChCondWithContext(_ *testing.T) { 43 | cond := newCond(&sync.Mutex{}) 44 | wg := sync.WaitGroup{} 45 | ctx, cancel := context.WithCancel(context.Background()) 46 | wg.Add(1) 47 | go func() { 48 | cond.L.Lock() 49 | cond.waitWithContext(ctx) 50 | cond.L.Unlock() 51 | wg.Done() 52 | }() 53 | cancel() 54 | wg.Wait() 55 | } 56 | -------------------------------------------------------------------------------- /pulsar/internal/checksum.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package internal 19 | 20 | import ( 21 | "hash" 22 | "hash/crc32" 23 | ) 24 | 25 | // crc32cTable holds the precomputed crc32 hash table 26 | // used by Pulsar (crc32c) 27 | var crc32cTable = crc32.MakeTable(crc32.Castagnoli) 28 | 29 | type CheckSum struct { 30 | hash hash.Hash 31 | } 32 | 33 | // Crc32cCheckSum handles computing the checksum. 34 | func Crc32cCheckSum(data []byte) uint32 { 35 | return crc32.Checksum(data, crc32cTable) 36 | } 37 | 38 | func (cs *CheckSum) Write(p []byte) (int, error) { 39 | if cs.hash == nil { 40 | cs.hash = crc32.New(crc32cTable) 41 | } 42 | return cs.hash.Write(p) 43 | } 44 | 45 | func (cs *CheckSum) compute() []byte { 46 | if cs.hash == nil { 47 | return nil 48 | } 49 | return cs.hash.Sum(nil) 50 | } 51 | -------------------------------------------------------------------------------- /pulsar/internal/checksum_test.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package internal 19 | 20 | import ( 21 | "bytes" 22 | "hash/crc32" 23 | "testing" 24 | ) 25 | 26 | func TestFrameChecksum(t *testing.T) { 27 | input := []byte{1, 2, 3, 4, 5} 28 | var f CheckSum 29 | 30 | if got := f.compute(); got != nil { 31 | t.Fatalf("compute() = %v; expected nil", got) 32 | } 33 | 34 | if _, err := f.Write(input); err != nil { 35 | t.Fatalf("Write() err = %v; expected nil", err) 36 | } 37 | 38 | h := crc32.New(crc32.MakeTable(crc32.Castagnoli)) 39 | if _, err := h.Write(input); err != nil { 40 | t.Fatal(err) 41 | } 42 | 43 | if got, expected := f.compute(), h.Sum(nil); !bytes.Equal(got, expected) { 44 | t.Fatalf("compute() = %x; expected %x", got, expected) 45 | } else { 46 | t.Logf("compute() = 0x%x", got) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /pulsar/internal/client_handlers.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package internal 19 | 20 | import "sync" 21 | 22 | // ClientHandlerMap is a simple concurrent-safe map for the client type 23 | type ClientHandlers struct { 24 | handlers map[Closable]bool 25 | l *sync.RWMutex 26 | } 27 | 28 | func NewClientHandlers() ClientHandlers { 29 | return ClientHandlers{ 30 | handlers: map[Closable]bool{}, 31 | l: &sync.RWMutex{}, 32 | } 33 | } 34 | func (h *ClientHandlers) Add(c Closable) { 35 | h.l.Lock() 36 | defer h.l.Unlock() 37 | h.handlers[c] = true 38 | } 39 | 40 | func (h *ClientHandlers) Del(c Closable) { 41 | h.l.Lock() 42 | defer h.l.Unlock() 43 | delete(h.handlers, c) 44 | } 45 | 46 | func (h *ClientHandlers) Val(c Closable) bool { 47 | h.l.RLock() 48 | defer h.l.RUnlock() 49 | return h.handlers[c] 50 | } 51 | 52 | func (h *ClientHandlers) Close() { 53 | h.l.Lock() 54 | handlers := make([]Closable, 0, len(h.handlers)) 55 | for handler := range h.handlers { 56 | handlers = append(handlers, handler) 57 | } 58 | h.l.Unlock() 59 | 60 | for _, handler := range handlers { 61 | handler.Close() 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /pulsar/internal/closable.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package internal 19 | 20 | type Closable interface { 21 | Close() 22 | } 23 | -------------------------------------------------------------------------------- /pulsar/internal/compression/compression.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package compression 19 | 20 | import "io" 21 | 22 | type Level int 23 | 24 | const ( 25 | Default Level = iota 26 | Faster 27 | Better 28 | ) 29 | 30 | // Provider is a interface of compression providers 31 | type Provider interface { 32 | // Return the max possible size for a compressed buffer given the uncompressed data size 33 | CompressMaxSize(originalSize int) int 34 | 35 | // Compress a []byte, the param is a []byte with the uncompressed content. 36 | // The reader/writer indexes will not be modified. The return is a []byte 37 | // with the compressed content. 38 | Compress(dst, src []byte) []byte 39 | 40 | // Decompress a []byte. The buffer needs to have been compressed with the matching Encoder. 41 | // The src is compressed content. If dst is passed, the decompressed data will be written there 42 | // The return were the result will be passed, if err is nil, the buffer was decompressed, no nil otherwise. 43 | Decompress(dst, src []byte, originalSize int) ([]byte, error) 44 | 45 | // Returns a new instance of the same provider, with the same exact configuration 46 | Clone() Provider 47 | 48 | // Close the compressor 49 | io.Closer 50 | } 51 | -------------------------------------------------------------------------------- /pulsar/internal/compression/noop.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package compression 19 | 20 | import ( 21 | "bytes" 22 | ) 23 | 24 | type noopProvider struct{} 25 | 26 | // NewNoopProvider returns a Provider interface that does not compress the data 27 | func NewNoopProvider() Provider { 28 | return &noopProvider{} 29 | } 30 | 31 | func (noopProvider) CompressMaxSize(originalSize int) int { 32 | return originalSize 33 | } 34 | 35 | func (noopProvider) Compress(dst, src []byte) []byte { 36 | if dst == nil { 37 | dst = make([]byte, len(src)) 38 | } 39 | 40 | b := bytes.NewBuffer(dst[:0]) 41 | b.Write(src) 42 | return dst[:len(src)] 43 | } 44 | 45 | func (noopProvider) Decompress(dst, src []byte, _ int) ([]byte, error) { 46 | if dst == nil { 47 | dst = make([]byte, len(src)) 48 | } 49 | 50 | b := bytes.NewBuffer(dst[:0]) 51 | b.Write(src) 52 | return dst[:len(src)], nil 53 | } 54 | 55 | func (noopProvider) Close() error { 56 | return nil 57 | } 58 | 59 | func (noopProvider) Clone() Provider { 60 | return NewNoopProvider() 61 | } 62 | -------------------------------------------------------------------------------- /pulsar/internal/compression/zstd.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | //go:build !cgo 19 | // +build !cgo 20 | 21 | package compression 22 | 23 | import ( 24 | "fmt" 25 | ) 26 | 27 | func NewZStdProvider(level Level) Provider { 28 | return newPureGoZStdProvider(level) 29 | } 30 | 31 | func newCGoZStdProvider(level Level) Provider { 32 | // This is kept to avoid compile errors in benchmark code when cgo is disabled. 33 | // The warning is only shown when running the benchmark with CGO disabled. 34 | fmt.Println("WARNING: CGO is disabled, using pure Go implementation of ZStd. Use CGO_ENABLED=1 when running benchmark.") 35 | return newPureGoZStdProvider(level) 36 | } 37 | -------------------------------------------------------------------------------- /pulsar/internal/crypto/consumer_decryptor.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package crypto 19 | 20 | import ( 21 | "fmt" 22 | 23 | "github.com/apache/pulsar-client-go/pulsar/crypto" 24 | pb "github.com/apache/pulsar-client-go/pulsar/internal/pulsar_proto" 25 | "github.com/apache/pulsar-client-go/pulsar/log" 26 | ) 27 | 28 | type consumerDecryptor struct { 29 | keyReader crypto.KeyReader 30 | messageCrypto crypto.MessageCrypto 31 | logger log.Logger 32 | } 33 | 34 | func NewConsumerDecryptor(keyReader crypto.KeyReader, 35 | messageCrypto crypto.MessageCrypto, 36 | logger log.Logger) Decryptor { 37 | return &consumerDecryptor{ 38 | keyReader: keyReader, 39 | messageCrypto: messageCrypto, 40 | logger: logger, 41 | } 42 | } 43 | 44 | func (d *consumerDecryptor) Decrypt(payload []byte, 45 | _ *pb.MessageIdData, 46 | msgMetadata *pb.MessageMetadata) ([]byte, error) { 47 | // encryption keys are not present in message metadta, no need decrypt the payload 48 | if len(msgMetadata.GetEncryptionKeys()) == 0 { 49 | return payload, nil 50 | } 51 | 52 | // KeyReader interface is not implemented 53 | if d.keyReader == nil { 54 | return payload, fmt.Errorf("KeyReader interface is not implemented") 55 | } 56 | 57 | return d.messageCrypto.Decrypt(crypto.NewMessageMetadataSupplier(msgMetadata), 58 | payload, 59 | d.keyReader) 60 | } 61 | -------------------------------------------------------------------------------- /pulsar/internal/crypto/decryptor.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package crypto 19 | 20 | import ( 21 | pb "github.com/apache/pulsar-client-go/pulsar/internal/pulsar_proto" 22 | ) 23 | 24 | // Decryptor support decrypting of message 25 | type Decryptor interface { 26 | Decrypt(payload []byte, msgID *pb.MessageIdData, msgMetadata *pb.MessageMetadata) ([]byte, error) 27 | } 28 | -------------------------------------------------------------------------------- /pulsar/internal/crypto/encryptor.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package crypto 19 | 20 | import ( 21 | pb "github.com/apache/pulsar-client-go/pulsar/internal/pulsar_proto" 22 | ) 23 | 24 | // Encryptor support encryption 25 | type Encryptor interface { 26 | Encrypt([]byte, *pb.MessageMetadata) ([]byte, error) 27 | } 28 | -------------------------------------------------------------------------------- /pulsar/internal/crypto/noop_decryptor.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package crypto 19 | 20 | import ( 21 | "fmt" 22 | 23 | pb "github.com/apache/pulsar-client-go/pulsar/internal/pulsar_proto" 24 | ) 25 | 26 | type noopDecryptor struct{} 27 | 28 | func NewNoopDecryptor() Decryptor { 29 | return &noopDecryptor{} 30 | } 31 | 32 | // Decrypt noop decryptor 33 | func (d *noopDecryptor) Decrypt(payload []byte, 34 | _ *pb.MessageIdData, 35 | msgMetadata *pb.MessageMetadata) ([]byte, error) { 36 | if len(msgMetadata.GetEncryptionKeys()) > 0 { 37 | return payload, fmt.Errorf("incoming message payload is encrypted, consumer is not configured to decrypt") 38 | } 39 | return payload, nil 40 | } 41 | -------------------------------------------------------------------------------- /pulsar/internal/crypto/noop_encryptor.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package crypto 19 | 20 | import ( 21 | pb "github.com/apache/pulsar-client-go/pulsar/internal/pulsar_proto" 22 | ) 23 | 24 | type noopEncryptor struct{} 25 | 26 | func NewNoopEncryptor() Encryptor { 27 | return &noopEncryptor{} 28 | } 29 | 30 | // Encrypt Noop ecryptor 31 | func (e *noopEncryptor) Encrypt(data []byte, _ *pb.MessageMetadata) ([]byte, error) { 32 | return data, nil 33 | } 34 | -------------------------------------------------------------------------------- /pulsar/internal/hash.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package internal 19 | 20 | import "github.com/spaolacci/murmur3" 21 | 22 | // JavaStringHash and Java String.hashCode() equivalent 23 | func JavaStringHash(s string) uint32 { 24 | var h uint32 25 | for i, size := 0, len(s); i < size; i++ { 26 | h = 31*h + uint32(s[i]) 27 | } 28 | 29 | return h 30 | } 31 | 32 | // Murmur3_32Hash use Murmur3 hashing function 33 | func Murmur3_32Hash(s string) uint32 { 34 | h := murmur3.New32() 35 | _, err := h.Write([]byte(s)) 36 | if err != nil { 37 | return 0 38 | } 39 | // Maintain compatibility with values used in Java client 40 | return h.Sum32() & 0x7fffffff 41 | } 42 | -------------------------------------------------------------------------------- /pulsar/internal/hash_test.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package internal 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/stretchr/testify/assert" 24 | ) 25 | 26 | type testProvider struct { 27 | str string 28 | 29 | hash uint32 30 | } 31 | 32 | var javaHashValues = []testProvider{ 33 | {"", 0x0}, 34 | {"hello", 0x5e918d2}, 35 | {"test", 0x364492}, 36 | } 37 | 38 | var murmurHashValues = []testProvider{ 39 | {"", 0x0}, 40 | {"hello", 0x248bfa47}, 41 | {"test", 0x3a6bd213}, 42 | } 43 | 44 | func TestJavaHash(t *testing.T) { 45 | for _, javaHashValue := range javaHashValues { 46 | p := javaHashValue 47 | t.Run(p.str, func(t *testing.T) { 48 | assert.Equal(t, p.hash, JavaStringHash(p.str)) 49 | }) 50 | } 51 | } 52 | 53 | func TestMurmurHash(t *testing.T) { 54 | for _, murmurHashValue := range murmurHashValues { 55 | p := murmurHashValue 56 | t.Run(p.str, func(t *testing.T) { 57 | assert.Equal(t, p.hash, Murmur3_32Hash(p.str)) 58 | }) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /pulsar/internal/helper.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package internal 19 | 20 | import "time" 21 | 22 | // These method should only be used by tests 23 | 24 | func StartCleanConnectionsTask(p *ConnectionPool, connectionMaxIdleTime time.Duration) { 25 | go (*p).(*connectionPool).checkAndCleanIdleConnections(connectionMaxIdleTime) 26 | } 27 | 28 | func GetConnectionsCount(p *ConnectionPool) int { 29 | pool := (*p).(*connectionPool) 30 | pool.Lock() 31 | defer pool.Unlock() 32 | return len(pool.connections) 33 | } 34 | -------------------------------------------------------------------------------- /pulsar/internal/namespace_name.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package internal 19 | 20 | import "strings" 21 | 22 | func IsV2Namespace(namespace string) bool { 23 | parts := strings.Split(namespace, "/") 24 | // Legacy namespace name that includes cluster name 25 | return len(parts) == 2 26 | } 27 | -------------------------------------------------------------------------------- /pulsar/internal/namespace_name_test.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package internal 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/stretchr/testify/assert" 24 | ) 25 | 26 | func TestIsV2Namespace(t *testing.T) { 27 | assert.True(t, IsV2Namespace("tenant/default")) 28 | assert.False(t, IsV2Namespace("tenant/cluster/default")) 29 | assert.False(t, IsV2Namespace("default")) 30 | } 31 | -------------------------------------------------------------------------------- /pulsar/internal/pulsar_proto/README.md: -------------------------------------------------------------------------------- 1 | protoc-gen-go: 2 | 3 | ```shell 4 | go install google.golang.org/protobuf/cmd/protoc-gen-go@latest 5 | ``` 6 | 7 | Generate code: 8 | 9 | ```shell 10 | protoc --go_out=. --go_opt=paths=source_relative PulsarApi.proto 11 | ``` -------------------------------------------------------------------------------- /pulsar/internal/pulsartracing/consumer_interceptor.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package pulsartracing 19 | 20 | import ( 21 | "context" 22 | 23 | "github.com/apache/pulsar-client-go/pulsar" 24 | "github.com/opentracing/opentracing-go" 25 | ) 26 | 27 | const fromPrefix = "From__" 28 | 29 | type ConsumerInterceptor struct { 30 | } 31 | 32 | func (t *ConsumerInterceptor) BeforeConsume(message pulsar.ConsumerMessage) { 33 | buildAndInjectChildSpan(message).Finish() 34 | } 35 | 36 | func (t *ConsumerInterceptor) OnAcknowledge(_ pulsar.Consumer, _ pulsar.MessageID) {} 37 | 38 | func (t *ConsumerInterceptor) OnNegativeAcksSend(_ pulsar.Consumer, _ []pulsar.MessageID) { 39 | } 40 | 41 | func buildAndInjectChildSpan(message pulsar.ConsumerMessage) opentracing.Span { 42 | tracer := opentracing.GlobalTracer() 43 | parentContext := ExtractSpanContextFromConsumerMessage(message) 44 | 45 | var span opentracing.Span 46 | 47 | var startSpanOptions []opentracing.StartSpanOption 48 | if parentContext != nil { 49 | startSpanOptions = []opentracing.StartSpanOption{opentracing.FollowsFrom(parentContext)} 50 | } 51 | 52 | span = tracer.StartSpan(fromPrefix+message.Topic()+"__"+message.Subscription(), startSpanOptions...) 53 | 54 | enrichConsumerSpan(&message, span) 55 | InjectConsumerMessageSpanContext(opentracing.ContextWithSpan(context.Background(), span), message) 56 | 57 | return span 58 | } 59 | -------------------------------------------------------------------------------- /pulsar/internal/pulsartracing/producer_interceptor.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package pulsartracing 19 | 20 | import ( 21 | "context" 22 | 23 | "github.com/apache/pulsar-client-go/pulsar" 24 | "github.com/opentracing/opentracing-go" 25 | ) 26 | 27 | const toPrefix = "To__" 28 | 29 | type ProducerInterceptor struct { 30 | } 31 | 32 | func (t *ProducerInterceptor) BeforeSend(producer pulsar.Producer, message *pulsar.ProducerMessage) { 33 | buildAndInjectSpan(message, producer).Finish() 34 | } 35 | 36 | func (t *ProducerInterceptor) OnSendAcknowledgement(_ pulsar.Producer, 37 | _ *pulsar.ProducerMessage, 38 | _ pulsar.MessageID) { 39 | } 40 | 41 | func buildAndInjectSpan(message *pulsar.ProducerMessage, producer pulsar.Producer) opentracing.Span { 42 | tracer := opentracing.GlobalTracer() 43 | spanContext := ExtractSpanContextFromProducerMessage(message) 44 | 45 | var span opentracing.Span 46 | 47 | var startSpanOptions []opentracing.StartSpanOption 48 | if spanContext != nil { 49 | startSpanOptions = []opentracing.StartSpanOption{opentracing.FollowsFrom(spanContext)} 50 | } 51 | 52 | span = tracer.StartSpan(toPrefix+producer.Topic(), startSpanOptions...) 53 | 54 | enrichProducerSpan(message, producer, span) 55 | 56 | InjectProducerMessageSpanContext(opentracing.ContextWithSpan(context.Background(), span), message) 57 | 58 | return span 59 | } 60 | -------------------------------------------------------------------------------- /pulsar/internal/pulsartracing/readme.md: -------------------------------------------------------------------------------- 1 | ### Usage 2 | 3 | #### Interceptors based solution 4 | 5 | ```go 6 | // create new tracer 7 | // register tracer with GlobalTracer 8 | opentracing.SetGlobalTracer(tracer) 9 | ``` 10 | 11 | **Producer** 12 | 13 | ```go 14 | tracingInterceptor := &pulsartracing.ProducerInterceptor{} 15 | 16 | options := pulsar.ProducerOptions{ 17 | Topic: topicName, 18 | Interceptors: pulsar.ProducerInterceptors{tracingInterceptor}, 19 | } 20 | ``` 21 | 22 | **Consumer** 23 | ```go 24 | tracingInterceptor := &pulsartracing.ConsumerInterceptor{} 25 | 26 | options := pulsar.ConsumerOptions{ 27 | Topics: topicName, 28 | SubscriptionName: subscriptionName, 29 | Type: pulsar.Shared, 30 | Interceptors: pulsar.ConsumerInterceptors{tracingInterceptor}, 31 | } 32 | 33 | 34 | // to create span with message as parent span 35 | span := pulsartracing.CreateSpanFromMessage(message, tracer, "child_span") 36 | ``` 37 | 38 | ## License 39 | 40 | [Apache 2.0 License](./../../../LICENSE). -------------------------------------------------------------------------------- /pulsar/internal/pulsartracing/span-enrichment.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package pulsartracing 19 | 20 | import ( 21 | "github.com/apache/pulsar-client-go/pulsar" 22 | "github.com/opentracing/opentracing-go" 23 | ) 24 | 25 | func enrichConsumerSpan(message *pulsar.ConsumerMessage, span opentracing.Span) { 26 | spanCommonTags(span) 27 | 28 | for k, v := range message.Properties() { 29 | span.SetTag(k, v) 30 | } 31 | span.SetTag("message_bus.destination", message.Topic()) 32 | span.SetTag("messageId", message.ID()) 33 | span.SetTag("subscription", message.Subscription()) 34 | } 35 | 36 | func enrichProducerSpan(message *pulsar.ProducerMessage, producer pulsar.Producer, span opentracing.Span) { 37 | spanCommonTags(span) 38 | 39 | for k, v := range message.Properties { 40 | span.SetTag(k, v) 41 | } 42 | span.SetTag("span.kind", "producer") 43 | span.SetTag("message_bus.destination", producer.Topic()) 44 | span.SetTag("sequenceId", producer.LastSequenceID()) 45 | } 46 | 47 | func spanCommonTags(span opentracing.Span) { 48 | span.SetTag("component", "pulsar-client-go") 49 | span.SetTag("peer.service", "pulsar-broker") 50 | } 51 | -------------------------------------------------------------------------------- /pulsar/internal/retry.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package internal 19 | 20 | import ( 21 | "context" 22 | "errors" 23 | "time" 24 | ) 25 | 26 | type OpFn[T any] func() (T, error) 27 | 28 | // Retry the given operation until the returned error is nil or the context is done. 29 | func Retry[T any](ctx context.Context, op OpFn[T], nextDuration func(error) time.Duration) (T, error) { 30 | var ( 31 | timer *time.Timer 32 | res T 33 | err error 34 | ) 35 | 36 | cleanTimer := func() { 37 | if timer != nil { 38 | timer.Stop() 39 | } 40 | } 41 | defer cleanTimer() 42 | 43 | for { 44 | res, err = op() 45 | if err == nil { 46 | return res, nil 47 | } 48 | 49 | duration := nextDuration(err) 50 | if timer == nil { 51 | timer = time.NewTimer(duration) 52 | } else { 53 | timer.Reset(duration) 54 | } 55 | 56 | select { 57 | case <-ctx.Done(): 58 | return res, errors.Join(ctx.Err(), err) 59 | case <-timer.C: 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /pulsar/internal/retry_test.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package internal 19 | 20 | import ( 21 | "context" 22 | "errors" 23 | "testing" 24 | "time" 25 | 26 | "github.com/stretchr/testify/require" 27 | ) 28 | 29 | func TestRetryWithCtxBackground(t *testing.T) { 30 | ctx := context.Background() 31 | i := 0 32 | res, err := Retry(ctx, func() (string, error) { 33 | if i == 2 { 34 | return "ok", nil 35 | } 36 | i++ 37 | return "", errors.New("error") 38 | }, func(_ error) time.Duration { 39 | return 1 * time.Second 40 | }) 41 | require.NoError(t, err) 42 | require.Equal(t, "ok", res) 43 | } 44 | 45 | func TestRetryWithCtxTimeout(t *testing.T) { 46 | ctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second) 47 | defer cancelFn() 48 | retryErr := errors.New("error") 49 | res, err := Retry(ctx, func() (string, error) { 50 | return "", retryErr 51 | }, func(err error) time.Duration { 52 | require.Equal(t, retryErr, err) 53 | return 1 * time.Second 54 | }) 55 | require.ErrorIs(t, err, context.DeadlineExceeded) 56 | require.ErrorContains(t, err, retryErr.Error()) 57 | require.Equal(t, "", res) 58 | } 59 | -------------------------------------------------------------------------------- /pulsar/internal/semaphore_test.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package internal 19 | 20 | import ( 21 | "context" 22 | "sync" 23 | "testing" 24 | "time" 25 | 26 | "github.com/stretchr/testify/assert" 27 | ) 28 | 29 | func TestSemaphore(t *testing.T) { 30 | s := NewSemaphore(3) 31 | 32 | const n = 10 33 | 34 | wg := sync.WaitGroup{} 35 | wg.Add(n) 36 | 37 | for i := 0; i < n; i++ { 38 | go func() { 39 | assert.True(t, s.Acquire(context.Background())) 40 | time.Sleep(100 * time.Millisecond) 41 | s.Release() 42 | wg.Done() 43 | }() 44 | } 45 | 46 | wg.Wait() 47 | } 48 | 49 | func TestSemaphore_TryAcquire(t *testing.T) { 50 | s := NewSemaphore(1) 51 | 52 | assert.True(t, s.Acquire(context.Background())) 53 | 54 | assert.False(t, s.TryAcquire()) 55 | 56 | s.Release() 57 | 58 | assert.True(t, s.TryAcquire()) 59 | assert.False(t, s.TryAcquire()) 60 | s.Release() 61 | } 62 | 63 | func TestSemaphore_ContextExpire(t *testing.T) { 64 | s := NewSemaphore(1) 65 | 66 | assert.True(t, s.Acquire(context.Background())) 67 | 68 | ctx, cancel := context.WithCancel(context.Background()) 69 | cancel() 70 | assert.False(t, s.Acquire(ctx)) 71 | 72 | assert.False(t, s.TryAcquire()) 73 | s.Release() 74 | 75 | assert.True(t, s.TryAcquire()) 76 | } 77 | -------------------------------------------------------------------------------- /pulsar/internal/version.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package internal 19 | 20 | import ( 21 | "runtime/debug" 22 | 23 | "golang.org/x/mod/semver" 24 | ) 25 | 26 | const ( 27 | pulsarClientGoModulePath = "github.com/apache/pulsar-client-go" 28 | ) 29 | 30 | var ( 31 | Version string 32 | ClientVersionString string 33 | ) 34 | 35 | // init Initializes the module version information by reading 36 | // the built in golang build info. If the application was not built 37 | // using go modules then the version string will not be available. 38 | func init() { 39 | if buildInfo, ok := debug.ReadBuildInfo(); ok { 40 | for _, dep := range buildInfo.Deps { 41 | if dep.Path == pulsarClientGoModulePath { 42 | Version = semver.Canonical(dep.Version) 43 | ClientVersionString = "Pulsar Go " + Version 44 | return 45 | } 46 | } 47 | } 48 | Version = "unknown" 49 | ClientVersionString = "Pulsar Go version unknown" 50 | } 51 | -------------------------------------------------------------------------------- /pulsar/internal/version_test.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package internal 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/stretchr/testify/assert" 24 | ) 25 | 26 | func TestInitVersion(t *testing.T) { 27 | assert.NotEmpty(t, Version, "version string should not be empty") 28 | } 29 | -------------------------------------------------------------------------------- /pulsar/message_test.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package pulsar 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/stretchr/testify/assert" 24 | ) 25 | 26 | func TestMessageZeroEventTime(t *testing.T) { 27 | msg := &ProducerMessage{} 28 | assert.Equal(t, false, msg.EventTime.UnixNano() == 0) 29 | assert.Equal(t, true, msg.EventTime.IsZero()) 30 | } 31 | -------------------------------------------------------------------------------- /pulsar/negative_backoff_policy.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package pulsar 19 | 20 | import ( 21 | "math" 22 | "time" 23 | ) 24 | 25 | // NackBackoffPolicy is a interface for custom message negativeAcked policy, users can specify a NackBackoffPolicy 26 | // for a consumer. 27 | // 28 | // > Notice: the consumer crashes will trigger the redelivery of the unacked message, this case will not respect the 29 | // > NackBackoffPolicy, which means the message might get redelivered earlier than the delay time 30 | // > from the backoff. 31 | type NackBackoffPolicy interface { 32 | // Next param redeliveryCount indicates the number of times the message was redelivered. 33 | // We can get the redeliveryCount from the CommandMessage. 34 | Next(redeliveryCount uint32) time.Duration 35 | } 36 | 37 | // defaultNackBackoffPolicy is default impl for NackBackoffPolicy. 38 | type defaultNackBackoffPolicy struct{} 39 | 40 | func (nbp *defaultNackBackoffPolicy) Next(redeliveryCount uint32) time.Duration { 41 | minNackTime := 1 * time.Second // 1sec 42 | maxNackTime := 10 * time.Minute // 10min 43 | 44 | if redeliveryCount < 0 { 45 | return minNackTime 46 | } 47 | 48 | return time.Duration(math.Min(math.Abs(float64(minNackTime< 0 { 50 | rootCA, err := os.ReadFile(config.TLSTrustCertsFilePath) 51 | if err != nil { 52 | return nil, err 53 | } 54 | tlsConfig.RootCAs = x509.NewCertPool() 55 | tlsConfig.RootCAs.AppendCertsFromPEM(rootCA) 56 | } 57 | transport.MaxIdleConnsPerHost = 10 58 | transport.TLSClientConfig = tlsConfig 59 | return transport, nil 60 | } 61 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/admin/config/api_version.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package config 19 | 20 | type APIVersion int 21 | 22 | const ( 23 | undefined APIVersion = iota 24 | V1 25 | V2 26 | V3 27 | ) 28 | 29 | const DefaultAPIVersion = "v2" 30 | 31 | func (v APIVersion) String() string { 32 | switch v { 33 | case undefined: 34 | return DefaultAPIVersion 35 | case V1: 36 | return "" 37 | case V2: 38 | return "v2" 39 | case V3: 40 | return "v3" 41 | } 42 | 43 | return DefaultAPIVersion 44 | } 45 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/admin/config/api_version_test.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package config 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/stretchr/testify/assert" 24 | ) 25 | 26 | func TestApiVersion_String(t *testing.T) { 27 | assert.Equal(t, "", V1.String()) 28 | assert.Equal(t, "v2", V2.String()) 29 | assert.Equal(t, "v3", V3.String()) 30 | var undefinedAPIVersion APIVersion 31 | assert.Equal(t, DefaultAPIVersion, undefinedAPIVersion.String()) 32 | } 33 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/admin/config/config.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package config 19 | 20 | type Config struct { 21 | // the web service url that pulsarctl connects to. Default is http://localhost:8080 22 | WebServiceURL string 23 | 24 | // the bookkeeper service url that pulsarctl connects to. 25 | BKWebServiceURL string 26 | // Set the path to the trusted TLS certificate file 27 | TLSTrustCertsFilePath string 28 | // Configure whether the Pulsar client accept untrusted TLS certificate from broker (default: false) 29 | TLSAllowInsecureConnection bool 30 | 31 | TLSEnableHostnameVerification bool 32 | 33 | AuthPlugin string 34 | 35 | AuthParams string 36 | 37 | // TLS Cert and Key Files for authentication 38 | TLSCertFile string 39 | TLSKeyFile string 40 | 41 | // Token and TokenFile is used to config the pulsarctl using token to authentication 42 | Token string 43 | TokenFile string 44 | PulsarAPIVersion APIVersion 45 | 46 | // OAuth2 configuration 47 | IssuerEndpoint string 48 | ClientID string 49 | Audience string 50 | KeyFile string 51 | Scope string 52 | } 53 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/rest/client_test.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package rest 19 | 20 | import ( 21 | "io" 22 | "testing" 23 | 24 | "github.com/stretchr/testify/require" 25 | ) 26 | 27 | func TestEncodeJSONBody(t *testing.T) { 28 | testcases := []struct { 29 | obj interface{} 30 | expected int 31 | }{ 32 | {obj: "1", expected: 3}, 33 | {obj: "12", expected: 4}, 34 | {obj: 1, expected: 1}, 35 | {obj: 12, expected: 2}, 36 | } 37 | 38 | for _, testcase := range testcases { 39 | r, err := encodeJSONBody(testcase.obj) 40 | require.NoError(t, err) 41 | 42 | b, err := io.ReadAll(r) 43 | require.NoError(t, err) 44 | 45 | require.Equal(t, testcase.expected, len(b)) 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/rest/errors.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package rest 19 | 20 | import "fmt" 21 | 22 | // Error is a admin error type 23 | type Error struct { 24 | Reason string `json:"reason"` 25 | Code int 26 | } 27 | 28 | func (e Error) Error() string { 29 | return fmt.Sprintf("code: %d reason: %s", e.Code, e.Reason) 30 | } 31 | 32 | func IsAdminError(err error) bool { 33 | _, ok := err.(Error) 34 | return ok 35 | } 36 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/auth_action.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | import "github.com/pkg/errors" 21 | 22 | type AuthAction string 23 | 24 | const ( 25 | produce AuthAction = "produce" 26 | consume AuthAction = "consume" 27 | functionsAuth AuthAction = "functions" 28 | packages AuthAction = "packages" 29 | sinks AuthAction = "sinks" 30 | sources AuthAction = "sources" 31 | ) 32 | 33 | func ParseAuthAction(action string) (AuthAction, error) { 34 | switch action { 35 | case "produce": 36 | return produce, nil 37 | case "consume": 38 | return consume, nil 39 | case "functions": 40 | return functionsAuth, nil 41 | case "packages": 42 | return packages, nil 43 | case "sinks": 44 | return sinks, nil 45 | case "sources": 46 | return sources, nil 47 | default: 48 | return "", errors.Errorf("The auth action only can be specified as 'produce', "+ 49 | "'consume', 'sources', 'sinks', 'packages', or 'functions'. Invalid auth action '%s'", action) 50 | } 51 | } 52 | 53 | func (a AuthAction) String() string { 54 | return string(a) 55 | } 56 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/auth_polices.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type AuthPolicies struct { 21 | NamespaceAuth map[string][]AuthAction `json:"namespace_auth"` 22 | DestinationAuth map[string]map[string][]AuthAction `json:"destination_auth"` 23 | SubscriptionAuthRoles map[string][]string `json:"subscription_auth_roles"` 24 | } 25 | 26 | func NewAuthPolicies() *AuthPolicies { 27 | return &AuthPolicies{ 28 | NamespaceAuth: make(map[string][]AuthAction), 29 | DestinationAuth: make(map[string]map[string][]AuthAction), 30 | SubscriptionAuthRoles: make(map[string][]string), 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/batch_source_config.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | const ( 21 | BatchsourceConfigKey string = "__BATCHSOURCECONFIGS__" 22 | BatchsourceClassnameKey string = "__BATCHSOURCECLASSNAME__" 23 | ) 24 | 25 | type BatchSourceConfig struct { 26 | DiscoveryTriggererClassName string `json:"discoveryTriggererClassName" yaml:"discoveryTriggererClassName"` 27 | 28 | DiscoveryTriggererConfig map[string]interface{} `json:"discoveryTriggererConfig" yaml:"discoveryTriggererConfig"` 29 | } 30 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/broker_ns_isolation_data.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type BrokerNamespaceIsolationData struct { 21 | BrokerName string `json:"brokerName"` 22 | PolicyName string `json:"policyName"` 23 | IsPrimary bool `json:"isPrimary"` 24 | NamespaceRegex []string `json:"namespaceRegex"` 25 | } 26 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/bundles_data.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type BundlesData struct { 21 | Boundaries []string `json:"boundaries"` 22 | NumBundles int `json:"numBundles"` 23 | } 24 | 25 | func NewBundlesData(boundaries []string) BundlesData { 26 | return BundlesData{ 27 | Boundaries: boundaries, 28 | NumBundles: len(boundaries) - 1, 29 | } 30 | } 31 | 32 | func NewBundlesDataWithNumBundles(numBundles int) *BundlesData { 33 | return &BundlesData{ 34 | Boundaries: nil, 35 | NumBundles: numBundles, 36 | } 37 | } 38 | 39 | func NewDefaultBoundle() *BundlesData { 40 | bundleData := NewBundlesDataWithNumBundles(1) 41 | bundleData.Boundaries = append(bundleData.Boundaries, FirstBoundary, LastBoundary) 42 | return bundleData 43 | } 44 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/connector_definition.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | // Basic information about a Pulsar connector 21 | type ConnectorDefinition struct { 22 | // The name of the connector type 23 | Name string `json:"name"` 24 | 25 | // Description to be used for user help 26 | Description string `json:"description"` 27 | 28 | // The class name for the connector source implementation 29 | //

If not defined, it will be assumed this connector cannot act as a data source 30 | SourceClass string `json:"sourceClass"` 31 | 32 | // The class name for the connector sink implementation 33 | //

If not defined, it will be assumed this connector cannot act as a data sink 34 | SinkClass string `json:"sinkClass"` 35 | } 36 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/consumer_config.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type ConsumerConfig struct { 21 | SchemaType string `json:"schemaType,omitempty" yaml:"schemaType"` 22 | SerdeClassName string `json:"serdeClassName,omitempty" yaml:"serdeClassName"` 23 | RegexPattern bool `json:"regexPattern,omitempty" yaml:"regexPattern"` 24 | ReceiverQueueSize int `json:"receiverQueueSize,omitempty" yaml:"receiverQueueSize"` 25 | SchemaProperties map[string]string `json:"schemaProperties,omitempty" yaml:"schemaProperties"` 26 | ConsumerProperties map[string]string `json:"consumerProperties,omitempty" yaml:"consumerProperties"` 27 | CryptoConfig *CryptoConfig `json:"cryptoConfig,omitempty" yaml:"cryptoConfig"` 28 | PoolMessages bool `json:"poolMessages,omitempty" yaml:"poolMessages"` 29 | } 30 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/crypto_config.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type CryptoConfig struct { 21 | CryptoKeyReaderClassName string `json:"cryptoKeyReaderClassName" yaml:"cryptoKeyReaderClassName"` 22 | CryptoKeyReaderConfig map[string]interface{} `json:"cryptoKeyReaderConfig" yaml:"cryptoKeyReaderConfig"` 23 | 24 | EncryptionKeys []string `json:"encryptionKeys" yaml:"encryptionKeys"` 25 | ProducerCryptoFailureAction string `json:"producerCryptoFailureAction" yaml:"producerCryptoFailureAction"` 26 | ConsumerCryptoFailureAction string `json:"consumerCryptoFailureAction" yaml:"consumerCryptoFailureAction"` 27 | } 28 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/dispatch_rate.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type DispatchRate struct { 21 | DispatchThrottlingRateInMsg int `json:"dispatchThrottlingRateInMsg"` 22 | DispatchThrottlingRateInByte int64 `json:"dispatchThrottlingRateInByte"` 23 | RatePeriodInSecond int `json:"ratePeriodInSecond"` 24 | } 25 | 26 | func NewDispatchRate() *DispatchRate { 27 | return &DispatchRate{ 28 | DispatchThrottlingRateInMsg: -1, 29 | DispatchThrottlingRateInByte: -1, 30 | RatePeriodInSecond: 1, 31 | } 32 | } 33 | 34 | type SubscribeRate struct { 35 | SubscribeThrottlingRatePerConsumer int `json:"subscribeThrottlingRatePerConsumer"` 36 | RatePeriodInSecond int `json:"ratePeriodInSecond"` 37 | } 38 | 39 | func NewSubscribeRate() *SubscribeRate { 40 | return &SubscribeRate{ 41 | SubscribeThrottlingRatePerConsumer: -1, 42 | RatePeriodInSecond: 30, 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/function_state.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type FunctionState struct { 21 | Key string `json:"key"` 22 | StringValue string `json:"stringValue,omitempty"` 23 | ByteValue []byte `json:"byteValue,omitempty"` 24 | NumValue int64 `json:"numberValue,omitempty"` 25 | Version int64 `json:"version,omitempty"` 26 | } 27 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/internal_configuration_data.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type InternalConfigurationData struct { 21 | ZookeeperServers string `json:"zookeeperServers"` 22 | ConfigurationStoreServers string `json:"configurationStoreServers"` 23 | LedgersRootPath string `json:"ledgersRootPath"` 24 | StateStorageServiceURL string `json:"stateStorageServiceUrl"` 25 | } 26 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/long_running_process_status.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type Status string 21 | 22 | const ( 23 | NOTRUN Status = "NOT_RUN" 24 | RUNNING Status = "RUNNING" 25 | SUCCESS Status = "SUCCESS" 26 | ERROR Status = "ERROR" 27 | ) 28 | 29 | type LongRunningProcessStatus struct { 30 | Status Status `json:"status"` 31 | LastError string `json:"lastError"` 32 | } 33 | 34 | type OffloadProcessStatus struct { 35 | Status Status `json:"status"` 36 | LastError string `json:"lastError"` 37 | FirstUnOffloadedMessage MessageID `json:"firstUnoffloadedMessage"` 38 | } 39 | 40 | func (s Status) String() string { 41 | return string(s) 42 | } 43 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/metrics.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type Metrics struct { 21 | Metrics map[string]interface{} `json:"metrics"` 22 | Dimensions map[string]string `json:"dimensions"` 23 | } 24 | 25 | func NewMetrics(dimensionMap map[string]string) *Metrics { 26 | return &Metrics{ 27 | Metrics: make(map[string]interface{}), 28 | Dimensions: dimensionMap, 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/ns_ownership_status.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type NamespaceOwnershipStatus struct { 21 | BrokerAssignment BrokerAssignment `json:"broker_assignment"` 22 | IsControlled bool `json:"is_controlled"` 23 | IsActive bool `json:"is_active"` 24 | } 25 | 26 | type BrokerAssignment string 27 | 28 | const ( 29 | Primary BrokerAssignment = "primary" 30 | Secondary BrokerAssignment = "secondary" 31 | Shared BrokerAssignment = "shared" 32 | ) 33 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/package_metadata.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type PackageMetadata struct { 21 | Description string `json:"description,omitempty" yaml:"description"` 22 | Contact string `json:"contact,omitempty" yaml:"contact"` 23 | CreateTime int64 `json:"createTime,omitempty" yaml:"createTime"` 24 | ModificationTime int64 `json:"modificationTime,omitempty" yaml:"modificationTime"` 25 | Properties map[string]string `json:"properties,omitempty" yaml:"properties"` 26 | } 27 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/package_type.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | import "github.com/pkg/errors" 21 | 22 | type PackageType string 23 | 24 | const ( 25 | PackageTypeFunction PackageType = "function" 26 | PackageTypeSink PackageType = "sink" 27 | PackageTypeSource PackageType = "source" 28 | ) 29 | 30 | func parsePackageType(packageTypeName string) (PackageType, error) { 31 | switch packageTypeName { 32 | case PackageTypeFunction.String(): 33 | return PackageTypeFunction, nil 34 | case PackageTypeSink.String(): 35 | return PackageTypeSink, nil 36 | case PackageTypeSource.String(): 37 | return PackageTypeSource, nil 38 | default: 39 | return "", errors.Errorf("Invalid package type '%s', it should be "+ 40 | "function, sink, or source", packageTypeName) 41 | } 42 | } 43 | 44 | func (p PackageType) String() string { 45 | return string(p) 46 | } 47 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/persistence_policies.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type PersistencePolicies struct { 21 | BookkeeperEnsemble int `json:"bookkeeperEnsemble"` 22 | BookkeeperWriteQuorum int `json:"bookkeeperWriteQuorum"` 23 | BookkeeperAckQuorum int `json:"bookkeeperAckQuorum"` 24 | ManagedLedgerMaxMarkDeleteRate float64 `json:"managedLedgerMaxMarkDeleteRate"` 25 | } 26 | 27 | func NewPersistencePolicies(bookkeeperEnsemble, bookkeeperWriteQuorum, bookkeeperAckQuorum int, 28 | managedLedgerMaxMarkDeleteRate float64) PersistencePolicies { 29 | return PersistencePolicies{ 30 | BookkeeperEnsemble: bookkeeperEnsemble, 31 | BookkeeperWriteQuorum: bookkeeperWriteQuorum, 32 | BookkeeperAckQuorum: bookkeeperAckQuorum, 33 | ManagedLedgerMaxMarkDeleteRate: managedLedgerMaxMarkDeleteRate, 34 | } 35 | } 36 | 37 | type BookieAffinityGroupData struct { 38 | BookkeeperAffinityGroupPrimary string `json:"bookkeeperAffinityGroupPrimary"` 39 | BookkeeperAffinityGroupSecondary string `json:"bookkeeperAffinityGroupSecondary"` 40 | } 41 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/producer_config.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type ProducerConfig struct { 21 | MaxPendingMessages int `json:"maxPendingMessages" yaml:"maxPendingMessages"` 22 | //nolint 23 | MaxPendingMessagesAcrossPartitions int `json:"maxPendingMessagesAcrossPartitions" yaml:"maxPendingMessagesAcrossPartitions"` 24 | 25 | UseThreadLocalProducers bool `json:"useThreadLocalProducers" yaml:"useThreadLocalProducers"` 26 | CryptoConfig *CryptoConfig `json:"cryptoConfig" yaml:"cryptoConfig"` 27 | BatchBuilder string `json:"batchBuilder" yaml:"batchBuilder"` 28 | CompressionType string `json:"compressionType" yaml:"compressionType"` 29 | } 30 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/publish_rate.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type PublishRate struct { 21 | PublishThrottlingRateInMsg int `json:"publishThrottlingRateInMsg"` 22 | PublishThrottlingRateInByte int64 `json:"publishThrottlingRateInByte"` 23 | } 24 | 25 | func NewPublishRate() *PublishRate { 26 | return &PublishRate{ 27 | PublishThrottlingRateInMsg: -1, 28 | PublishThrottlingRateInByte: -1, 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/resource_quota.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type ResourceQuota struct { 21 | // messages published per second 22 | MsgRateIn float64 `json:"msgRateIn"` 23 | // messages consumed per second 24 | MsgRateOut float64 `json:"msgRateOut"` 25 | // incoming bytes per second 26 | BandwidthIn float64 `json:"bandwidthIn"` 27 | // outgoing bytes per second 28 | BandwidthOut float64 `json:"bandwidthOut"` 29 | // used memory in Mbytes 30 | Memory float64 `json:"memory"` 31 | // allow the quota be dynamically re-calculated according to real traffic 32 | Dynamic bool `json:"dynamic"` 33 | } 34 | 35 | func NewResourceQuota() *ResourceQuota { 36 | return &ResourceQuota{ 37 | MsgRateIn: 0.0, 38 | MsgRateOut: 0.0, 39 | BandwidthIn: 0.0, 40 | BandwidthOut: 0.0, 41 | Memory: 0.0, 42 | Dynamic: true, 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/resources.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type Resources struct { 21 | CPU float64 `json:"cpu"` 22 | Disk int64 `json:"disk"` 23 | RAM int64 `json:"ram"` 24 | } 25 | 26 | func NewDefaultResources() *Resources { 27 | resources := &Resources{ 28 | // Default cpu is 1 core 29 | CPU: 1, 30 | // Default memory is 1GB 31 | RAM: 1073741824, 32 | // Default disk is 10GB 33 | Disk: 10737418240, 34 | } 35 | 36 | return resources 37 | } 38 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/retention_policies.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type RetentionPolicies struct { 21 | RetentionTimeInMinutes int `json:"retentionTimeInMinutes"` 22 | RetentionSizeInMB int64 `json:"retentionSizeInMB"` 23 | } 24 | 25 | func NewRetentionPolicies(retentionTimeInMinutes int, retentionSizeInMB int) RetentionPolicies { 26 | return RetentionPolicies{ 27 | RetentionTimeInMinutes: retentionTimeInMinutes, 28 | RetentionSizeInMB: int64(retentionSizeInMB), 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/source_status.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type SourceStatus struct { 21 | NumInstances int `json:"numInstances"` 22 | NumRunning int `json:"numRunning"` 23 | Instances []*SourceInstanceStatus `json:"instances"` 24 | } 25 | 26 | type SourceInstanceStatus struct { 27 | InstanceID int `json:"instanceId"` 28 | Status SourceInstanceStatusData `json:"status"` 29 | } 30 | 31 | type SourceInstanceStatusData struct { 32 | Running bool `json:"running"` 33 | Err string `json:"error"` 34 | NumRestarts int64 `json:"numRestarts"` 35 | NumReceivedFromSource int64 `json:"numReceivedFromSource"` 36 | NumSystemExceptions int64 `json:"numSystemExceptions"` 37 | LatestSystemExceptions []ExceptionInformation `json:"latestSystemExceptions"` 38 | NumSourceExceptions int64 `json:"numSourceExceptions"` 39 | LatestSourceExceptions []ExceptionInformation `json:"latestSourceExceptions"` 40 | NumWritten int64 `json:"numWritten"` 41 | LastReceivedTime int64 `json:"lastReceivedTime"` 42 | WorkerID string `json:"workerId"` 43 | } 44 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/subscription_auth_mode.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | import "github.com/pkg/errors" 21 | 22 | type SubscriptionAuthMode string 23 | 24 | const ( 25 | None SubscriptionAuthMode = "None" 26 | Prefix SubscriptionAuthMode = "Prefix" 27 | ) 28 | 29 | func ParseSubscriptionAuthMode(s string) (SubscriptionAuthMode, error) { 30 | switch s { 31 | case "None": 32 | return None, nil 33 | case "Prefix": 34 | return Prefix, nil 35 | default: 36 | return "", errors.New("Invalid subscription auth mode") 37 | } 38 | } 39 | 40 | func (s SubscriptionAuthMode) String() string { 41 | return string(s) 42 | } 43 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/topic_auto_creation_config.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type TopicAutoCreationConfig struct { 21 | Allow bool `json:"allowAutoTopicCreation"` 22 | Type TopicType `json:"topicType"` 23 | Partitions *int `json:"defaultNumPartitions"` 24 | } 25 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/topic_domain.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | import "github.com/pkg/errors" 21 | 22 | type TopicDomain string 23 | 24 | const ( 25 | persistent TopicDomain = "persistent" 26 | nonPersistent TopicDomain = "non-persistent" 27 | ) 28 | 29 | func ParseTopicDomain(domain string) (TopicDomain, error) { 30 | switch domain { 31 | case "persistent": 32 | return persistent, nil 33 | case "non-persistent": 34 | return nonPersistent, nil 35 | default: 36 | return "", errors.Errorf("The domain only can be specified as 'persistent' or "+ 37 | "'non-persistent'. Input domain is '%s'.", domain) 38 | } 39 | } 40 | 41 | func (t TopicDomain) String() string { 42 | return string(t) 43 | } 44 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/topic_type.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | import "github.com/pkg/errors" 21 | 22 | type TopicType string 23 | 24 | const ( 25 | Partitioned TopicType = "partitioned" 26 | NonPartitioned TopicType = "non-partitioned" 27 | ) 28 | 29 | func ParseTopicType(topicType string) (TopicType, error) { 30 | switch topicType { 31 | case "partitioned": 32 | return Partitioned, nil 33 | case "non-partitioned": 34 | return NonPartitioned, nil 35 | default: 36 | return "", errors.Errorf("The topic type can only be specified as 'partitioned' or "+ 37 | "'non-partitioned'. Input topic type is '%s'.", topicType) 38 | } 39 | } 40 | 41 | func (t TopicType) String() string { 42 | return string(t) 43 | } 44 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/topics_stats_stream.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | // var TopicsMap map[string]map[string]map[string]TopicStats 21 | 22 | type TopicStatsStream struct { 23 | TopicsMap map[string]map[string]map[string]TopicStats `json:"topicStatsBuf"` 24 | } 25 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/update_options.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | // Options while updating the sink 21 | type UpdateOptions struct { 22 | UpdateAuthData bool 23 | } 24 | 25 | func NewUpdateOptions() *UpdateOptions { 26 | return &UpdateOptions{ 27 | UpdateAuthData: false, 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/utils.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | import ( 21 | "fmt" 22 | "os" 23 | "reflect" 24 | ) 25 | 26 | func MakeHTTPPath(apiVersion string, componentPath string) string { 27 | return fmt.Sprintf("/admin/%s%s", apiVersion, componentPath) 28 | } 29 | 30 | func IsNilFixed(i interface{}) bool { 31 | if i == nil { 32 | return true 33 | } 34 | switch reflect.TypeOf(i).Kind() { 35 | case reflect.Ptr, reflect.Map, reflect.Array, reflect.Chan, reflect.Slice: 36 | return reflect.ValueOf(i).IsNil() 37 | } 38 | return false 39 | } 40 | 41 | func GetConfigPath() string { 42 | // pulsar client config dir path, for example: PULSAR_CLIENT_CONF_PATH: /home/pulsar 43 | // configuration file path is: /home/pulsar/.config/pulsar 44 | if envConf, ok := os.LookupEnv("PULSAR_CLIENT_CONF_PATH"); ok { 45 | return envConf 46 | } 47 | return HomeDir() 48 | } 49 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/utils_test.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/stretchr/testify/assert" 24 | ) 25 | 26 | type People interface { 27 | MakeSound() string 28 | } 29 | 30 | type Student struct{} 31 | 32 | func (s *Student) MakeSound() string { 33 | return "Student" 34 | } 35 | 36 | type Teacher struct{} 37 | 38 | func (t Teacher) MakeSound() string { 39 | return "Teacher" 40 | } 41 | 42 | // nolint 43 | func TestIsNilFixed(t *testing.T) { 44 | var stu *Student = nil 45 | var people People 46 | people = stu 47 | 48 | var teacher Teacher 49 | people = teacher 50 | 51 | assert.False(t, IsNilFixed(people)) 52 | 53 | var m map[string]string 54 | assert.True(t, IsNilFixed(m)) 55 | 56 | var s []string 57 | assert.True(t, IsNilFixed(s)) 58 | 59 | var ch chan string 60 | assert.True(t, IsNilFixed(ch)) 61 | 62 | var nilInterface People 63 | assert.True(t, IsNilFixed(nilInterface)) 64 | 65 | // pointer to an interface, the IsNilFixed method cannot check this. 66 | assert.False(t, IsNilFixed(&nilInterface)) 67 | } 68 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/window_confing.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | const WindowConfigKey = "__WINDOWCONFIGS__" 21 | 22 | type WindowConfig struct { 23 | WindowLengthCount *int `json:"windowLengthCount" yaml:"windowLengthCount"` 24 | WindowLengthDurationMs *int64 `json:"windowLengthDurationMs" yaml:"windowLengthDurationMs"` 25 | SlidingIntervalCount *int `json:"slidingIntervalCount" yaml:"slidingIntervalCount"` 26 | SlidingIntervalDurationMs *int64 `json:"slidingIntervalDurationMs" yaml:"slidingIntervalDurationMs"` 27 | LateDataTopic *string `json:"lateDataTopic" yaml:"lateDataTopic"` 28 | MaxLagMs *int64 `json:"maxLagMs" yaml:"maxLagMs"` 29 | WatermarkEmitIntervalMs *int64 `json:"watermarkEmitIntervalMs" yaml:"watermarkEmitIntervalMs"` 30 | TimestampExtractorClassName *string `json:"timestampExtractorClassName" yaml:"timestampExtractorClassName"` 31 | ActualWindowFunctionClassName *string `json:"actualWindowFunctionClassName" yaml:"actualWindowFunctionClassName"` 32 | ProcessingGuarantees *string `json:"processingGuarantees" yaml:"processingGuarantees"` 33 | } 34 | 35 | func NewDefaultWindowConfing() *WindowConfig { 36 | windowConfig := &WindowConfig{} 37 | 38 | return windowConfig 39 | } 40 | -------------------------------------------------------------------------------- /pulsaradmin/pkg/utils/worker_info.go: -------------------------------------------------------------------------------- 1 | // Licensed to the Apache Software Foundation (ASF) under one 2 | // or more contributor license agreements. See the NOTICE file 3 | // distributed with this work for additional information 4 | // regarding copyright ownership. The ASF licenses this file 5 | // to you under the Apache License, Version 2.0 (the 6 | // "License"); you may not use this file except in compliance 7 | // with the License. You may obtain a copy of the License at 8 | // 9 | // http://www.apache.org/licenses/LICENSE-2.0 10 | // 11 | // Unless required by applicable law or agreed to in writing, 12 | // software distributed under the License is distributed on an 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | // KIND, either express or implied. See the License for the 15 | // specific language governing permissions and limitations 16 | // under the License. 17 | 18 | package utils 19 | 20 | type WorkerInfo struct { 21 | WorkerID string `json:"workerId"` 22 | WorkerHostname string `json:"workerHostname"` 23 | Port int `json:"port"` 24 | } 25 | 26 | type WorkerFunctionInstanceStats struct { 27 | Name string `json:"name"` 28 | Metrics FunctionInstanceStatsData `json:"metrics"` 29 | } 30 | -------------------------------------------------------------------------------- /scripts/pulsar-test-service-stop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | 19 | 20 | set -e 21 | 22 | SRC_DIR=$(git rev-parse --show-toplevel) 23 | cd $SRC_DIR 24 | 25 | IMAGE_NAME=pulsar-client-go-test:latest 26 | 27 | if [[ -f /.dockerenv ]]; then 28 | # When running tests inside docker 29 | /pulsar/bin/pulsar-daemon stop standalone 30 | else 31 | docker kill pulsar-client-go-test 32 | fi 33 | 34 | echo "Stopped Test Pulsar Service" 35 | -------------------------------------------------------------------------------- /scripts/run-ci-blue-green-cluster.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | 19 | set -x 20 | set -o pipefail 21 | 22 | TEST_LOG=/tmp/test-log-$(date +%s).log 23 | 24 | # Default values for test configuration 25 | : "${TEST_RACE:=1}" 26 | : "${TEST_COVERAGE:=0}" 27 | 28 | # Build the test command dynamically 29 | TEST_CMD="go test" 30 | if [ "$TEST_RACE" = "1" ]; then 31 | TEST_CMD="$TEST_CMD -race" 32 | fi 33 | if [ "$TEST_COVERAGE" = "1" ]; then 34 | TEST_CMD="$TEST_CMD -coverprofile=/tmp/coverage-blue_green_topic_migration" 35 | fi 36 | TEST_CMD="$TEST_CMD -timeout=5m -tags extensible_load_manager -v -run TestBlueGreenMigrationTestSuite ./pulsar" 37 | 38 | $TEST_CMD 2>&1 | tee $TEST_LOG 39 | retval=$? 40 | if [ $retval -ne 0 ]; then 41 | # Make it easier to find out which test failed 42 | echo "Tests failed" 43 | grep -- "--- FAIL: " $TEST_LOG 44 | exit $retval 45 | else 46 | echo "Tests passed" 47 | if [ "$TEST_COVERAGE" = "1" ]; then 48 | go tool cover -html=/tmp/coverage-blue_green_topic_migration -o coverage-blue_green_topic_migration.html 49 | fi 50 | fi -------------------------------------------------------------------------------- /scripts/run-ci-clustered.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | 19 | set -x 20 | set -o pipefail 21 | 22 | TEST_LOG=/tmp/test-log-$(date +%s).log 23 | 24 | # Default values for test configuration 25 | : "${TEST_RACE:=1}" 26 | : "${TEST_COVERAGE:=0}" 27 | 28 | # Build the test command dynamically 29 | TEST_CMD="go test" 30 | if [ "$TEST_RACE" = "1" ]; then 31 | TEST_CMD="$TEST_CMD -race" 32 | fi 33 | if [ "$TEST_COVERAGE" = "1" ]; then 34 | TEST_CMD="$TEST_CMD -coverprofile=/tmp/coverage" 35 | fi 36 | TEST_CMD="$TEST_CMD -timeout=5m -tags clustered -v -run 'Test.*ClusteredTestSuite|TestTransactionDisabled' -v ./pulsar" 37 | 38 | $TEST_CMD 2>&1 | tee $TEST_LOG 39 | retval=$? 40 | if [ $retval -ne 0 ]; then 41 | # Make it easier to find out which test failed 42 | echo "Tests failed" 43 | grep -- "--- FAIL: " $TEST_LOG 44 | exit $retval 45 | else 46 | echo "Tests passed" 47 | if [ "$TEST_COVERAGE" = "1" ]; then 48 | go tool cover -html=/tmp/coverage -o coverage.html 49 | fi 50 | fi 51 | 52 | -------------------------------------------------------------------------------- /scripts/run-ci-extensible-load-manager.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | 19 | set -x 20 | set -o pipefail 21 | 22 | TEST_LOG=/tmp/test-log-$(date +%s).log 23 | 24 | # Default values for test configuration 25 | : "${TEST_RACE:=1}" 26 | : "${TEST_COVERAGE:=0}" 27 | 28 | # Build the test command dynamically 29 | TEST_CMD="go test" 30 | if [ "$TEST_RACE" = "1" ]; then 31 | TEST_CMD="$TEST_CMD -race" 32 | fi 33 | if [ "$TEST_COVERAGE" = "1" ]; then 34 | TEST_CMD="$TEST_CMD -coverprofile=/tmp/coverage" 35 | fi 36 | TEST_CMD="$TEST_CMD -timeout=5m -tags extensible_load_manager -v -run TestExtensibleLoadManagerTestSuite ./pulsar" 37 | 38 | $TEST_CMD 2>&1 | tee $TEST_LOG 39 | retval=$? 40 | if [ $retval -ne 0 ]; then 41 | # Make it easier to find out which test failed 42 | echo "Tests failed" 43 | grep -- "--- FAIL: " $TEST_LOG 44 | exit $retval 45 | else 46 | echo "Tests passed" 47 | if [ "$TEST_COVERAGE" = "1" ]; then 48 | go tool cover -html=/tmp/coverage -o coverage.html 49 | fi 50 | fi 51 | 52 | -------------------------------------------------------------------------------- /scripts/run-ci.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | 19 | 20 | set -x 21 | set -o pipefail 22 | 23 | scripts/pulsar-test-service-start.sh 24 | 25 | trap scripts/pulsar-test-service-stop.sh EXIT 26 | 27 | TEST_LOG=/tmp/test-log-$(date +%s).log 28 | 29 | export CGO_ENABLED=1 30 | 31 | # Default values for test configuration 32 | # Set TEST_RACE=0 to disable race detector 33 | # Set TEST_COVERAGE=0 to disable coverage 34 | : "${TEST_RACE:=1}" 35 | : "${TEST_COVERAGE:=0}" 36 | 37 | # Build the test command dynamically 38 | TEST_CMD="go test" 39 | if [ "$TEST_RACE" = "1" ]; then 40 | TEST_CMD="$TEST_CMD -race" 41 | fi 42 | if [ "$TEST_COVERAGE" = "1" ]; then 43 | TEST_CMD="$TEST_CMD -coverprofile=/tmp/coverage" 44 | fi 45 | TEST_CMD="$TEST_CMD -timeout=20m -v ./..." 46 | 47 | $TEST_CMD 2>&1 | tee $TEST_LOG 48 | retval=$? 49 | if [ $retval -ne 0 ]; then 50 | # Make it easier to find out which test failed 51 | echo "Tests failed" 52 | grep -- "--- FAIL: " $TEST_LOG 53 | exit $retval 54 | else 55 | echo "Tests passed" 56 | if [ "$TEST_COVERAGE" = "1" ]; then 57 | go tool cover -html=/tmp/coverage -o coverage.html 58 | fi 59 | fi 60 | -------------------------------------------------------------------------------- /scripts/stage-release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | 19 | set -euo pipefail 20 | 21 | if [ $# -ne 2 ]; then 22 | echo "Usage: $0 " 23 | exit 1 24 | fi 25 | 26 | VERSION=$1 27 | 28 | DEST_PATH=$2 29 | DEST_PATH="$(cd "$DEST_PATH" && pwd)" 30 | 31 | pushd "$(dirname "$0")" 32 | REPO_PATH=$(git rev-parse --show-toplevel) 33 | popd 34 | 35 | pushd "$REPO_PATH" 36 | git archive --format=tar.gz --output="$DEST_PATH/apache-pulsar-client-go-$VERSION-src.tar.gz" HEAD 37 | popd 38 | 39 | # Sign all files 40 | cd "$DEST_PATH" 41 | gpg -b --armor apache-pulsar-client-go-$VERSION-src.tar.gz 42 | shasum -a 512 apache-pulsar-client-go-$VERSION-src.tar.gz > apache-pulsar-client-go-$VERSION-src.tar.gz.sha512 43 | 44 | --------------------------------------------------------------------------------