### Install toxiproxy-java with Maven Source: https://github.com/trekawek/toxiproxy-java/blob/master/README.md This XML snippet shows how to add the toxiproxy-java client library as a dependency to your Maven project. Include this within the section of your pom.xml file to enable the library's functionalities and access its classes. ```XML eu.rekawek.toxiproxy toxiproxy-java 2.1.7 ``` -------------------------------- ### Initialize ToxiproxyClient in Java Source: https://github.com/trekawek/toxiproxy-java/blob/master/README.md This Java code demonstrates how to create an instance of ToxiproxyClient. By default, it connects to http://localhost:8474, but you can specify a custom host and port for the Toxiproxy server using the parameterized constructor, allowing connection to remote or non-standard Toxiproxy instances. ```Java ToxiproxyClient client = new ToxiproxyClient("192.168.1.1", 8474); ``` -------------------------------- ### Create a New Proxy for MySQL in Java Source: https://github.com/trekawek/toxiproxy-java/blob/master/README.md This Java snippet illustrates how to create a new proxy using the ToxiproxyClient. It sets up a proxy named 'mysql' that listens on localhost:21212 and forwards traffic to the actual MySQL service at localhost:3306. This allows for intercepting and manipulating traffic to the target service. ```Java Proxy mysqlProxy = client.createProxy("mysql", "localhost:21212", "localhost:3306"); ``` -------------------------------- ### Add Latency Toxic to a Proxy in Java Source: https://github.com/trekawek/toxiproxy-java/blob/master/README.md This Java code demonstrates how to add a 'latency' toxic to an existing proxy. The toxic, named 'my-latency-toxic', introduces a 100ms delay to downstream traffic and adds a jitter of 15ms. Toxics are used to simulate various network conditions like latency, bandwidth limits, or disconnections for testing resilience. ```Java mysqlProxy.toxics().latency("my-latency-toxic", DOWNSTREAM, 100).setJitter(15); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.