Giter VIP home page Giter VIP logo

clj-pcp-client's Introduction

clj-pcp-client

PCP client

https://github.com/puppetlabs/pcp-specifications

Installation

Releases of this project are distributed via clojars, to use it:

Clojars Project

Usage example

(ns example-client
  (:require [clojure.tools.logging :as log]
            [puppetlabs.pcp.client :as client]
            [puppetlabs.pcp.message-v2 :as message]))

(defn cnc-request-handler
  [conn request]
  (log/info "cnc handler got message" request)
  (let [response (-> (message/make-message)
                     (assoc :target (:sender request)
                            :message_type "example/cnc_response")
                     (message/set-data {:response "Hello world"
                                        :request (:id request)}))]
    (client/send! conn response))
  (log/info "cnc handler sent response"))

(defn default-request-handler
  [conn request]
  (log/info "Default handler got message" request))

;; connecting with handlers; allows an optional callback that's called when the
;; connection closes that passes the Client object as an argument
(def conn (client/connect
           {:server "wss://localhost:8142/pcp/"
            :ssl-context
            {:cert "test-resources/ssl/certs/0001_controller.pem"
             :private-key "test-resources/ssl/private_keys/0001_controller.pem"
             :cacert "test-resources/ssl/certs/ca.pem"}
            :on-close-cb (fn [client] (println client))}
           {"example/cnc_request" cnc-request-handler
            :default default-request-handler}))

;; ensuring that the underlying WebSocket connection persists with a heartbeat task
(client/start-heartbeat-thread conn)

;; sending messages
(client/send! conn
              (-> (message/make-message)
                  (assoc :target "pcp://*/demo-client"
                         :message_type "example/any_schema")))

(client/send! conn
              (-> (message/make-message)
                  (assoc :target "pcp://*/demo-client"
                         :message_type "example/cnc_request")
                  (message/set-data {:action "demo"})))

;; wait 5 seconds for things to resolve
(Thread/sleep (* 5 1000))

;; closing the connection and terminating the heartbeat task
(client/close conn)

Maintenance

Maintainers: Alessandro Parisi [email protected], Michael Smith [email protected], Michal Ruzicka [email protected].

Contributing: Please refer to this document.

Tickets: File bug tickets at https://tickets.puppet.com/browse/PCP and add the clj-pcp-client component to the ticket.

clj-pcp-client's People

Contributors

adreyer avatar barriserloth avatar donoghuc avatar jelinwils avatar jonathannewman avatar kbarber avatar mcdonaldseanp avatar mikaelsmith avatar mruzicka avatar mwaggett avatar nicklewis avatar parisiale avatar ploubser avatar puppetlabs-jenkins avatar richardc avatar rileynewton avatar samwoods1 avatar steveax avatar transifex-bot avatar wkalt avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.