Dear Reader,
This Blog is closed and remains as an archive.
Please find our new Blog at http://cleancode.consulting/
Donnerstag, 27. Februar 2020
Montag, 7. Oktober 2019
How to create Nav with Angular + Angular Material
To setup a basic navigation in Angular Material, type the following command in your terminal (e.g. I am using WebStorm IDE):
$ ng generate @angular/material:material.nav -name=main-nav
This will create a component named main-nav with all basic elements, fully responsive and free to modify.
$ ng generate @angular/material:material.nav -name=main-nav
This will create a component named main-nav with all basic elements, fully responsive and free to modify.
Dienstag, 10. September 2019
Find Color for CSS layout in Dreamweaver - Hex Value with Color Picker
If you need the color from an image, just
background-color: <type Ctrl + Enter> ;
The value will appear in your CSS, e.g.:
background-color: #25787F ;
Voilà!
- enter the color attribute in your CSS, e.g.
background-color: <type Ctrl + Enter> ;
- Choose the color-selection option,
- choose Color picker and
- place it above the image.
- Press Enter.
The value will appear in your CSS, e.g.:
background-color: #25787F ;
Voilà!
Freitag, 6. September 2019
RESTful Java Jersey JAX-RS Unit Test embedded Jetty Maven Webapp Download
HOWTO create a Java Webapp with JSON, REST and UNIT Test
RESTful Java Jersey JAX-RS Unit Test embedded Jetty Maven Webapp Download.DOWNLOAD Source Code
Mittwoch, 21. August 2019
Docker Compose Webapps Port Forwarding
Multiple Webapps Inside Docker Compose Setup
- Learn how to setup a custom network for your containers: container A talks to container B
- Learn how to run multiple webapps inside Docker containers on different ports with Docker Compose
- Create the network with $docker network create skynet
- Run with $docker-compose up
- Stop with $<Ctrl + C>
- Clean up from time to time (beware, network will be deleted as well) with $docker system prune -a -f
- access via http://localhost:8080/sample
- access via http://localhost:8081/sample
Dienstag, 20. August 2019
Docker How To Map Ports To Tomcat Application Server
How to map ports to your Tomcat application server in Docker.
Example uses Tomcat 7.
Adapt to your tomcat directory if using another version.
In Dockerfile:
#start Tomcat and map Port 8080 to Container Port 8080
RUN sed -i 's/port="8080"/port="8080"/' /opt/apache/tomcat/conf/server.xml
URL: http://localhost:8080
Example 8081:
#start Tomcat and map Port 8080 to Container Port 8081
URL: http://localhost:8081
Example uses Tomcat 7.
Adapt to your tomcat directory if using another version.
In Dockerfile:
#start Tomcat and map Port 8080 to Container Port 8080
RUN sed -i 's/port="8080"/port="8080"/' /opt/apache/tomcat/conf/server.xml
URL: http://localhost:8080
Example 8081:
#start Tomcat and map Port 8080 to Container Port 8081
RUN sed -i 's/port="8080"/port="8081"/' /opt/apache/tomcat/conf/server.xml
URL: http://localhost:8081
Mittwoch, 14. August 2019
Docker - How to shrink large Docker Images.
Some images become very big - one reason being that multiple RUN commands will create a layer and keep the data there. No removal.
Example:
RUN unzip myfile.war -d mynewdirectory/
RUN zip -r myfile.war mynewdirectory/
RUN mv myfile.war somedirectory
The myfile.war will be kept. It will not be deleted by the mv command.
Reason: Docker will create a layer for each RUN command.
Solution:
RUN unzip myfile.war -d mynewdirectory/ &&\
zip -r myfile.war mynewdirectory/ &&\
mv myfile.war somedirectory
Keep everything in one layer by utilizing concatenation with '&&\'.
WARNING:
Docker is highly optimized and based on Checksums.
If everything is concatenated, building an image can take very long.
Example: COPY or ADD will check wether a change in the underlying files or source code has been made and only execute if a change is detected.
Through concatenation, you reap Docker of the benefits regarding optimization (e.g. Checksums). No check. Everything is executed.
It is a good practice to keep this in mind when concatenating instrunctions.
Example:
RUN unzip myfile.war -d mynewdirectory/
RUN zip -r myfile.war mynewdirectory/
RUN mv myfile.war somedirectory
The myfile.war will be kept. It will not be deleted by the mv command.
Reason: Docker will create a layer for each RUN command.
Solution:
RUN unzip myfile.war -d mynewdirectory/ &&\
zip -r myfile.war mynewdirectory/ &&\
mv myfile.war somedirectory
Keep everything in one layer by utilizing concatenation with '&&\'.
WARNING:
Docker is highly optimized and based on Checksums.
If everything is concatenated, building an image can take very long.
Example: COPY or ADD will check wether a change in the underlying files or source code has been made and only execute if a change is detected.
Through concatenation, you reap Docker of the benefits regarding optimization (e.g. Checksums). No check. Everything is executed.
It is a good practice to keep this in mind when concatenating instrunctions.
Donnerstag, 1. August 2019
How to make Virtualbox available on Windows via localhost
Sometimes fate forces us to work with Windows.
Because Linux is so good, we get a VirtualBox to emulate it.
How can we access a webapplication via localhost:8080 from the Windows machine inside of a Webbrowser?
VirtualBox Manager -> VM-Tools -> Settings -> Network -> Port Forwarding
Name: http8080
Protocol: TCP
HostIP: empty
Host-Port: 8080
Guest-IP: empty
Guest-Port: 8080
Name: ssh
Protocol: TCP
HostIP: 127.0.0.1
Host-Port: 2222
Guest-IP: empty
Guest-Port: 22
Because Linux is so good, we get a VirtualBox to emulate it.
How can we access a webapplication via localhost:8080 from the Windows machine inside of a Webbrowser?
VirtualBox Manager -> VM-Tools -> Settings -> Network -> Port Forwarding
Name: http8080
Protocol: TCP
HostIP: empty
Host-Port: 8080
Guest-IP: empty
Guest-Port: 8080
Name: ssh
Protocol: TCP
HostIP: 127.0.0.1
Host-Port: 2222
Guest-IP: empty
Guest-Port: 22
Mittwoch, 24. Juli 2019
Howto create Docker Network with Docker Compose - Communication between Services inside of a Container
Create your network named 'yournetwork':
$ docker network create -d bridge yournetwork
You have created your own network now.
Verify it by typing
$network inspect yournetwork:
In the docker-compose.yml:
networks:
yournetwork: #TODO remove this hard-coded network reference
external:
name: ${NETWORK}
yourservice:
container_name: "your-container-name"
image: your-image-name:${TAG:-latest} #will pull the latest #tagged image of yours
ports:
- 8080:8080 #example localhost:8080
net: ${NETWORK}
Start it with:
$ NETWORK=yournetwork docker-compose-up
$ docker network create -d bridge yournetwork
You have created your own network now.
Verify it by typing
$network inspect yournetwork:
In the docker-compose.yml:
networks:
yournetwork: #TODO remove this hard-coded network reference
external:
name: ${NETWORK}
yourservice:
container_name: "your-container-name"
image: your-image-name:${TAG:-latest} #will pull the latest #tagged image of yours
ports:
- 8080:8080 #example localhost:8080
net: ${NETWORK}
Start it with:
$ NETWORK=yournetwork docker-compose-up
Dienstag, 23. Juli 2019
[Solution] Maven Proxy Issue - Maven not downloading artifacts - Maven behind Proxy
Your settings.xml - mine is in etc/maven/settings.xml on Linux - must look like:
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<settings
xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>myRepository</id>
<username>your user</username>
<password>your pw</password>
<configuration>
<httpConfiguration>
<all>
<usePreemptive>true</usePreemptive>
</all>
<settings>
</settings>
</httpConfiguration>
</configuration>
</server>
</servers>
<mirrors>
<mirror>
<id>myRepository</id>
<name>Proxy for XY</name>
<url>http://<maven proxy url></url>
<mirrorOf>*,!sonar</mirrorOf>
</mirror>
</mirrors>
<profiles>
</profiles>
</settings>
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<settings
xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>myRepository</id>
<username>your user</username>
<password>your pw</password>
<configuration>
<httpConfiguration>
<all>
<usePreemptive>true</usePreemptive>
</all>
<settings>
</settings>
</httpConfiguration>
</configuration>
</server>
</servers>
<mirrors>
<mirror>
<id>myRepository</id>
<name>Proxy for XY</name>
<url>http://<maven proxy url></url>
<mirrorOf>*,!sonar</mirrorOf>
</mirror>
</mirrors>
<profiles>
</profiles>
</settings>
Donnerstag, 18. Juli 2019
DOCKER - No Space Left on Device // How to clean Docker on Linux
Sometimes Docker will simply claim to much space. Time for a clean up ;)
Attention: if your network is not in the default, this command will eventually erase your subnet immediately.
docker system prune -a -f
Attention: if your network is not in the default, this command will eventually erase your subnet immediately.
Montag, 17. Juni 2019
Intellij Order Of Imports
IntelliJ sometimes changes the appearance of imports in the code on checkout when organizing imports.
To control that, one can adjust the settings:
Settings -> Editor -> Code Style -> Java -> Layout static imports separately
Change the order as you need, IntelliJ will sort the imports accordingly.
To control that, one can adjust the settings:
Settings -> Editor -> Code Style -> Java -> Layout static imports separately
Change the order as you need, IntelliJ will sort the imports accordingly.
Getting Gradle Dependencies in IntelliJ IDEA
Gradle Project Import
- Import the project as a Gradle project from within Idea.
- When you add a dependency you need to open the Gradle window and perform a refresh
Gradle Wrapper
- IntelliJ will ask you to auto-import Gradle in some cases. This can be done.
- Gradle Wrapper - many environments will use this wrapper to maintain the same standard between the different environments and stages. How to:
Ctrl + Shift + Alt + S → Import Module → Import Module from external model → Choose Gradle →
For Gradle Home: Use gradle 'wrapper' task configuration.
Donnerstag, 13. Juni 2019
Kafka vs. MQ + JMS - Difference Apache Kafka and MQ, RabbitMQ, ActiveMQ, JMS
Kafka is a messaging system. From the ground up it has been designed to provide high throughput, fast performance, scalability and high availability.
Here are the basics:
Here are the basics:
- Producers of the messages publishes to the Topics
- Consumers subscribes to the Topics
- Messages are array of bytes. They can be JSON objects, Strings etc
- Topics are logs of messages
- Kafka is run as a Cluster of servers each of which is called a Broker
In Kafka there is no concept of Queue and hence no
send or receive for putting/getting messages from the queue. Publish-subscribe
is the only paradigm available as a messaging model. Producers of the
messages Publisha message to the Topic and Consumer receives
messages by Subscribing to the topic. This publish-subscribe
paradigm is very similar between MQ/JMS and Kafka - the difference is under the
covers that we will discuss next.
2. Message Persistence
Typical JMS providers (IBM MQ, Rabbit MQ, Active MQ ..)
implement the topics in a such way that the messages published to the topic are
sent to a common storage (memory or/and persistent store) from where they are
picked up by the subscribers. In MQ/JMS systems once the message is read it is
removed from the storage and is no more available. Kafka retains the messages
even after all the subscribers have read the message. The rentention period is
a configurable parameter.
In a typical MQ/JMS consumer implementation, the
message is deleted by the messaging system on receiving an ACK/Commit. If for
some reason the message gets processed but fails before the ACK/Commit, it
would lead to message being read more than once. This problem has been
addressed by Kafka by way of message retention and state management based on
the consumer offset.
3. Topic partitioning
Kafka has implemented the topics as partitioned logs.
A partition is an ordered, immutable sequence of messages that is continually
appended to. This is similar to database log, for that reason
the partition is also referred to as the commit-log. This is
one of the biggest difference between MQ/JMS and Kafka. The partitioning of the
topic leads to its high throughput (and parallelism).
·
Partitions for the same topic are distributed across multiple brokers in
the cluster
·
Partitions are replicated across multiple servers; number of replicas is a
configurable parameter
·
Each Partition has one server as a leader and a number of
servers as followers
·
Each Server acts a leader for some of its partitions and as a follower for
some other
·
The Producers are responsible for choosing which message to assign to which
partition within the topic based on key assigned to message.
5. Message sequencing
In MQ/JMS there is no gurantee that the messages will
be received in a sequence in which they were sent. In Kafka though the sequence
is maintained at a partition level. In other words if the topic is configured
with a single partition then the messages are received in the same order that
they were sent in.
6. Message reads
The consumer of the messages in Kafka issues a fetch
request to the broker leading the partition it wants to consume. As part of the
fetch, consumer specifies the offset from which the message in the log is read
from. This is very different from the MQ/JMS messaging system where First In
First Out (FIFO) is the way messages are read off the queue/topic. The other
thing that happens is that with offset based control, the consumer can re-read
the same message which is not possible in MQ/JMS (yes you can do it with browse
but that is not what it is intended for).
This rewinding mechanism can be very handy in some
situation. E.g., if you received a batch of messages and processed it with
buggy code, you may fix the code and re-run the processing on the messages by
resetting the offset.
7. Load balancing
In the case of MQ/JMS the load balancing required messaging systems to be designed
using some clustering mechanism and the onus of distributing the load across
the cluster members was on the producer sending the messages. The Kafka nodes
publish the metadata which tells the producer which servers are alive in the
cluster, where the leader for the partitions are. This allows the client to
send message to the appropriate server (and partition) thus distributing the
message load across the cluster members.
8. Automatic failover & High
availability
Traditional MQ/JMS implementations did not have the
concept of message replication but some systems built it over a period of time;
those replication features at most times were not leveraged in favor of
simplicity. In Kafka, as decribed earlier the messages are replicated
(leader-followers) for each topic's partitions across a configurable number of
servers. This inherently leads to an architecture that provides automatic
failover to replica thus leading to high availability.
Zookeeper
Zookeeper plays a central role in this replication
mechanism. The follower servers maintain a session to zookeeper and respond to
the heartbeat messages. The slaves/replicas continuously read messages from the
leader as fast as they can as to not fall behind. The leader if discovers that
the slave is lagging removes it as the replica; this is determined by way of
configurable parameters. The message is considered committed when
all replicas are in sync with the leader. This sync aspect is also
configurable.
The state of the replication is managed by the leader
server and leader may drop the replica/slave if the replica is lagging too far
behind or is unresponsive.
Labels:
active mq,
activemq,
apache,
apache kafka,
bridging,
broker,
consumer,
difference,
enterprise bus,
enterprisebus,
jms,
kafka,
messagequeue,
messaging,
partitioning,
producer,
rabbit mq,
rabbitmq,
series,
topics
Montag, 27. Mai 2019
My Advice to Founders + Anyone Starting Their Own Business
Here is my advice when you are about to start your own business.
No matter what business you start, at a certain level it is all the same.
#1 Get a Coach
Look for someone who is able to help you out by giving advice to you. The best thing was if this person has already achieved what you want to achieve. For instance, my own Coach is successfully running multiple companies. It may cost you money but investing in yourself is the best thing you can do!
#2 Manage yourself as a boss and employee in one.
Enjoy the freedom and flexibility regarding time, appointments and mindset - you are your own boss now. Because of this: negotiate clever and be tough as nails regarding your ressource planning, even more with yourself ;)
#3 Go with the flow
It is easier for me to accept the limits or moods of my employees than accepting my own. But if I hit the floor because of sleep deprivation or anxiety, my business will go down, too. Thus:
#4 Be kind to yourself
... as you do already have proven that you have the courage to walk your own path. Being kind to yourself will help you to not crack under the pressure.
#5 Fun is the most important thing
Life is too short. Never forget that stress is a powerful force. Do always remember that fun is what this is about. The rest will follow - #lawOfAttraction .
Wish you much success with your business and all the best!
Tim
Mittwoch, 15. Mai 2019
How to remove line breaks etc. in Java String
myString.trim() .replace("\n", "") .replace("\r", "") .replace(System.getProperty("line.separator"), "");
Montag, 29. April 2019
Spring Security - get User Name
If you want to retrieve the name of a logged in user, do this:
private String getUserName() {import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.UserDetails;
Object principal = SecurityContextHolder
.getContext()
.getAuthentication()
.getPrincipal();
String userName;
if (principal instanceof UserDetails) {
userName = ((UserDetails)principal).getUsername();
} else {
userName = principal.toString();
}
return userName;
}
Mittwoch, 24. April 2019
Recover and Restore System Properties with Java - JUnit and more - Free program
Sometimes it is necessary to change System Properties. Maybe for a Test or something else. This program and test will recover and restore the System Properties to their initial state.
The program and test may be used freely under GNU General Public License Version and is brought to you by Harder IT Consulting www.harder-it-consulting.de
Donnerstag, 18. April 2019
Remove duplicates in list with Java > 8
//remove duplicates from a list with Java 8 or greater
mylist.stream().distinct.collect(Collectors.toList())
Mittwoch, 17. April 2019
Mock static methods with Mockito in Java (mock, static, method, java)
import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.BDDMockito; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class) @PrepareForTest(MyStatic.class) ... @Test
public void someTest() {
//given
PowerMockito.mockStatic(MyStatic.class); BDDMockito.given(MyStatic.someStaticMethod()).willReturn(...); //when ... //then
PowerMockito.verifyStatic(); MyStatic.someStaticMethod(); assertThat(//your further asserts....
Abonnieren
Posts (Atom)
NEW BLOG! http://cleancode.consulting/
Dear Reader, This Blog is closed and remains as an archive. Please find our new Blog at http://cleancode.consulting/
-
This is a fine one: if you only do have XML and nothing else, you can generate an XSD from the XML ( here ) and use the XSD to generate your...
-
Create your network named 'yournetwork': $ docker network create -d bridge yournetwork You have created your own network now. ...